Class SimpleLogger
- java.lang.Object
-
- org.slf4j.helpers.AbstractLogger
-
- org.slf4j.helpers.LegacyAbstractLogger
-
- io.microlam.slf4j.simple.SimpleLogger
-
- All Implemented Interfaces:
Serializable,org.slf4j.Logger
public class SimpleLogger extends org.slf4j.helpers.LegacyAbstractLoggerSimple implementation of
Loggerthat sends all enabled log messages, for all defined loggers, to the console (System.err). The following system properties are supported to configure the behavior of this logger:org.slf4j.simpleLogger.logFile- The output target which can be the path to a file, or the special values "LAMBDA", "System.out" and "System.err". Default is "LAMBDA".org.slf4j.simpleLogger.cacheOutputStream- If the output target is set to "System.out" or "System.err" (see preceding entry), by default, logs will be output to the latest value referenced bySystem.out/errvariables. By setting this parameter to true, the output stream will be cached, i.e. assigned once at initialization time and re-used independently of the current value referenced bySystem.out/err.org.slf4j.simpleLogger.defaultLogLevel- Default log level for all instances of SimpleLogger. Must be one of ("trace", "debug", "info", "warn", "error" or "off"). If not specified, defaults to "info".org.slf4j.simpleLogger.log.a.b.c- Logging detail level for a SimpleLogger instance named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent logger will be used, and if none is set, then the value specified byorg.slf4j.simpleLogger.defaultLogLevelwill be used.org.slf4j.simpleLogger.showAWSRequestId- Set totrueif you want to output the current aws request id. Defaults to true but really applicable only whenorg.slf4j.simpleLogger.logFile=LAMBDA.org.slf4j.simpleLogger.showDateTime- Set totrueif you want the current date and time to be included in output messages. Default isfalseorg.slf4j.simpleLogger.dateTimeFormat- The date and time format to be used in the output messages. The pattern describing the date and time format is defined bySimpleDateFormat. If the format is not specified or is invalid, the number of milliseconds since start up will be output.org.slf4j.simpleLogger.showThreadName-Set totrueif you want to output the current thread name. Defaults totrue.org.slf4j.simpleLogger.showLogName- Set totrueif you want the Logger instance name to be included in output messages. Defaults totrue.org.slf4j.simpleLogger.showShortLogName- Set totrueif you want the last component of the name to be included in output messages. Defaults tofalse.org.slf4j.simpleLogger.levelInBrackets- Should the level string be output in brackets? Defaults tofalse.org.slf4j.simpleLogger.warnLevelString- The string value output for the warn level. Defaults toWARN.
In addition to looking for system properties with the names specified above, this implementation also checks for a class loader resource named
"simplelogger.properties", and includes any matching definitions from this resource (if it exists).With no configuration, the default output includes the relative time in milliseconds, thread name, the level, logger name, and the message followed by the line separator for the host. In log4j terms it amounts to the "%r [%t] %level %logger - %m%n" pattern.
Sample output follows.
176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order. 225 [main] INFO examples.SortAlgo - Entered the sort method. 304 [main] INFO examples.SortAlgo - Dump of integer array: 317 [main] INFO examples.SortAlgo - Element [0] = 0 331 [main] INFO examples.SortAlgo - Element [1] = 1 343 [main] INFO examples.Sort - The next log statement should be an error message. 346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array. at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58) at org.log4j.examples.Sort.main(Sort.java:64) 467 [main] INFO examples.Sort - Exiting main method.
This implementation is heavily inspired by Apache Commons Logging's SimpleLog.
- Author:
- Ceki Gülcü, Scott Sanders, Rod Waldhoff, Robert Burrell Donkin, Cédrik LIME, Frank Afriat
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringCACHE_OUTPUT_STREAM_STRING_KEYprotected intcurrentLogLevelThe current log levelstatic StringDATE_TIME_FORMAT_KEYstatic StringDEFAULT_LOG_LEVEL_KEYstatic StringLEVEL_IN_BRACKETS_KEYstatic StringLOG_FILE_KEYstatic StringLOG_KEY_PREFIXprotected static intLOG_LEVEL_DEBUGprotected static intLOG_LEVEL_ERRORprotected static intLOG_LEVEL_INFOprotected static intLOG_LEVEL_OFFprotected static intLOG_LEVEL_TRACEprotected static intLOG_LEVEL_WARNprotected org.slf4j.spi.MDCAdaptermdcAdapterstatic StringSHOW_AWS_REQUEST_ID_KEYstatic StringSHOW_DATE_TIME_KEYstatic StringSHOW_LOG_NAME_KEYstatic StringSHOW_SHORT_LOG_NAME_KEYstatic StringSHOW_THREAD_NAME_KEYstatic StringSYSTEM_PREFIXAll system properties used bySimpleLoggerstart with this prefixstatic StringWARN_LEVEL_STRING_KEY
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringgetFullyQualifiedCallerName()protected voidhandleNormalizedLoggingCall(org.slf4j.event.Level level, org.slf4j.Marker marker, String messagePattern, Object[] arguments, Throwable t)This is our internal implementation for logging regular (non-parameterized) log messages.booleanisDebugEnabled()Aredebugmessages currently enabled?booleanisErrorEnabled()Areerrormessages currently enabled?booleanisInfoEnabled()Areinfomessages currently enabled?protected booleanisLevelEnabled(int logLevel)Is the given log level currently enabled?booleanisTraceEnabled()Aretracemessages currently enabled?booleanisWarnEnabled()Arewarnmessages currently enabled?voidlog(org.slf4j.event.LoggingEvent event)protected voidwriteThrowable(Throwable t, PrintStream targetStream)protected voidwriteWithThrowable(StringBuilder buf, Throwable t, com.amazonaws.services.lambda.runtime.LambdaLogger lambdaLogger)-
Methods inherited from class org.slf4j.helpers.LegacyAbstractLogger
isDebugEnabled, isErrorEnabled, isInfoEnabled, isTraceEnabled, isWarnEnabled
-
Methods inherited from class org.slf4j.helpers.AbstractLogger
debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, error, error, error, error, error, error, error, error, error, error, getName, info, info, info, info, info, info, info, info, info, info, readResolve, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
-
-
-
-
Field Detail
-
LOG_LEVEL_TRACE
protected static final int LOG_LEVEL_TRACE
- See Also:
- Constant Field Values
-
LOG_LEVEL_DEBUG
protected static final int LOG_LEVEL_DEBUG
- See Also:
- Constant Field Values
-
LOG_LEVEL_INFO
protected static final int LOG_LEVEL_INFO
- See Also:
- Constant Field Values
-
LOG_LEVEL_WARN
protected static final int LOG_LEVEL_WARN
- See Also:
- Constant Field Values
-
LOG_LEVEL_ERROR
protected static final int LOG_LEVEL_ERROR
- See Also:
- Constant Field Values
-
LOG_LEVEL_OFF
protected static final int LOG_LEVEL_OFF
- See Also:
- Constant Field Values
-
mdcAdapter
protected org.slf4j.spi.MDCAdapter mdcAdapter
-
currentLogLevel
protected int currentLogLevel
The current log level
-
SYSTEM_PREFIX
public static final String SYSTEM_PREFIX
All system properties used bySimpleLoggerstart with this prefix- See Also:
- Constant Field Values
-
LOG_KEY_PREFIX
public static final String LOG_KEY_PREFIX
- See Also:
- Constant Field Values
-
CACHE_OUTPUT_STREAM_STRING_KEY
public static final String CACHE_OUTPUT_STREAM_STRING_KEY
- See Also:
- Constant Field Values
-
WARN_LEVEL_STRING_KEY
public static final String WARN_LEVEL_STRING_KEY
- See Also:
- Constant Field Values
-
LEVEL_IN_BRACKETS_KEY
public static final String LEVEL_IN_BRACKETS_KEY
- See Also:
- Constant Field Values
-
LOG_FILE_KEY
public static final String LOG_FILE_KEY
- See Also:
- Constant Field Values
-
SHOW_SHORT_LOG_NAME_KEY
public static final String SHOW_SHORT_LOG_NAME_KEY
- See Also:
- Constant Field Values
-
SHOW_LOG_NAME_KEY
public static final String SHOW_LOG_NAME_KEY
- See Also:
- Constant Field Values
-
SHOW_THREAD_NAME_KEY
public static final String SHOW_THREAD_NAME_KEY
- See Also:
- Constant Field Values
-
SHOW_AWS_REQUEST_ID_KEY
public static final String SHOW_AWS_REQUEST_ID_KEY
- See Also:
- Constant Field Values
-
DATE_TIME_FORMAT_KEY
public static final String DATE_TIME_FORMAT_KEY
- See Also:
- Constant Field Values
-
SHOW_DATE_TIME_KEY
public static final String SHOW_DATE_TIME_KEY
- See Also:
- Constant Field Values
-
DEFAULT_LOG_LEVEL_KEY
public static final String DEFAULT_LOG_LEVEL_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
writeThrowable
protected void writeThrowable(Throwable t, PrintStream targetStream)
-
writeWithThrowable
protected void writeWithThrowable(StringBuilder buf, Throwable t, com.amazonaws.services.lambda.runtime.LambdaLogger lambdaLogger)
-
isLevelEnabled
protected boolean isLevelEnabled(int logLevel)
Is the given log level currently enabled?- Parameters:
logLevel- is this level enabled?- Returns:
- whether the logger is enabled for the given level
-
isTraceEnabled
public boolean isTraceEnabled()
Aretracemessages currently enabled?
-
isDebugEnabled
public boolean isDebugEnabled()
Aredebugmessages currently enabled?
-
isInfoEnabled
public boolean isInfoEnabled()
Areinfomessages currently enabled?
-
isWarnEnabled
public boolean isWarnEnabled()
Arewarnmessages currently enabled?
-
isErrorEnabled
public boolean isErrorEnabled()
Areerrormessages currently enabled?
-
handleNormalizedLoggingCall
protected void handleNormalizedLoggingCall(org.slf4j.event.Level level, org.slf4j.Marker marker, String messagePattern, Object[] arguments, Throwable t)This is our internal implementation for logging regular (non-parameterized) log messages.- Specified by:
handleNormalizedLoggingCallin classorg.slf4j.helpers.AbstractLogger- Parameters:
level- One of the LOG_LEVEL_XXX constants defining the log levelmessagePattern- The message itselft- The exception whose stack trace should be logged
-
log
public void log(org.slf4j.event.LoggingEvent event)
-
getFullyQualifiedCallerName
protected String getFullyQualifiedCallerName()
- Specified by:
getFullyQualifiedCallerNamein classorg.slf4j.helpers.AbstractLogger
-
-