Java slf4j Logger logLine(final Logger logger, final Level level, final String msg, final boolean withStackTrace, final String logMessagePrefix)

Here you can find the source of logLine(final Logger logger, final Level level, final String msg, final boolean withStackTrace, final String logMessagePrefix)

Description

Directly log msg to desired Logger .

License

Open Source License

Parameter

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

Declaration

public static void logLine(final Logger logger, final Level level, final String msg,
        final boolean withStackTrace, final String logMessagePrefix) 

Method Source Code


//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);
            }
        }
    }
}

Related

  1. loggerWithName(Class klass, String name)
  2. logInfo(Logger log)
  3. logInfo(Logger log, Throwable t)
  4. logInfo(Logger logger, String s)
  5. logJavaProperties(Logger log)
  6. logResult(long time, String traceId, String apiName, String params, String jsonObject)
  7. logThreadGroup(final Logger log, ThreadGroup group, int level)
  8. logThrowable(Throwable throwable)
  9. logWarningWithDebugDetails(Logger logger, Throwable t, String message, Object... values)