Here you can find the source of logLine(final Logger logger, final Level level, final String msg, final boolean withStackTrace, final String logMessagePrefix)
Parameter | Description |
---|---|
logger | the Logger which should be used for logging |
level | the log- Level to be used |
msg | the message to log |
withStackTrace | true=log include current stack trace |
logMessagePrefix | messagePreFix |
public static void logLine(final Logger logger, final Level level, final String msg, final boolean withStackTrace, final String logMessagePrefix)
//package com.java2s; //License from project: Open Source License import java.util.logging.Level; import org.slf4j.Logger; public class Main { /**/*w ww . ja v a 2 s . c o m*/ * Directly log msg to desired {@link Logger}. * * @param logger the {@link Logger} which should be used for logging * @param level the log-{@link Level} to be used * @param msg the message to log * @param withStackTrace * true=log include current stack trace * @param logMessagePrefix messagePreFix */ public static void logLine(final Logger logger, final Level level, final String msg, final boolean withStackTrace, final String logMessagePrefix) { final String finalMsg = logMessagePrefix + msg; if (level == Level.INFO) { if (withStackTrace) { logger.info(finalMsg, new Throwable()); } else { logger.info(finalMsg); } } else if (level == Level.SEVERE) { if (withStackTrace) { logger.error(finalMsg, new Throwable()); } else { logger.error(finalMsg); } } else if (level == Level.WARNING) { if (withStackTrace) { logger.warn(finalMsg, new Throwable()); } else { logger.warn(finalMsg); } } else if (level == Level.FINE || level == Level.FINER || level == Level.FINEST) { if (withStackTrace) { logger.debug(finalMsg, new Throwable()); } else { logger.debug(finalMsg); } } } }