Class LoggerEx
java.lang.Object
com.inductiveautomation.ignition.common.util.LoggerEx
- Direct Known Subclasses:
ReportExecutionContext.ReportLoggerEx
This class is a wrapper around a logger which provides additional useful tools. To create one, use the newBuilder()
function and configure the builder.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected classprotected classprotected static enumstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.commons.lang3.builder.ToStringStyleprotected org.slf4j.Markerprotected ObjectThe ident object to tack onto the beginning of all log messages (may be null).protected booleanSet this to true if you want the ident object to be to-stringed for each log messageprotected StringThe stored toString of the ident object (may be null)protected org.slf4j.LoggerThe underlying loggerprotected Object[]protected org.apache.commons.lang3.builder.ToStringStyleThe style to use to turn the ident obj into a string -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateMessage(String message, Object... args) createSubLogger(Class<?> clazz) createSubLogger(String name) Creates a child logger that extends from the current name, with the same identity object, event marker, and MDC context.voidvoiddebugDuration(String message) Duration trackers log start and finish times for operations.voiddebugEvent(String message, Object... args) Logs a debug message with the event marker defined on the logger.voidvoidvoidvoidvoiderrorEvent(String message, Object... args) Logs an error message with the event marker defined on the logger.voidvoidvoidvoidvoidvoidprotected Stringorg.apache.log4j.LoggerDeprecated.org.slf4j.LoggergetName()org.apache.commons.lang3.builder.ToStringStylevoidvoidinfoDuration(String message) Duration trackers log start and finish times for operations.voidLogs an info message with the event marker defined on the logger.voidvoidbooleanbooleanbooleanbooleanstatic voidlog(Class<?> clazz, LoggerEx.Level level, MDCUtils.MDCDetails mdc, String message, Object... args) Deprecated.voidmdcClose()The complementary function to mdcSet, if the AutoClosable return of the set function wasn't used.voidConvenience function that calls MDC putmdcPutClosable(String key, String value) voidConvenience function that calls MDC removemdcSet()Sets the registered mdc key/value pairs and returns a closable that can be used to unset them.static LoggerEx.Builderprotected voidsetEventMarker(org.slf4j.Marker marker) voidsetIdentObject(Object identObj) voidsetIdentObjectIsMutable(boolean identObjectIsMutable) protected voidsetLog(org.slf4j.Logger log) protected voidsetStaticMDCContextValues(Object... values) A set of key/value pairs that will be set and unset in the mdc context around each logging operation.voidsetToStringStyle(org.apache.commons.lang3.builder.ToStringStyle toStringStyle) voidvoidtraceDuration(String message) Duration trackers log start and finish times for operations.voidtraceEvent(String message, Object... args) Logs a trace message with the event marker defined on the logger.voidvoidvoidvoidvoidLogs a warning message with the event marker defined on the logger.voidvoid
-
Field Details
-
log
protected org.slf4j.Logger logThe underlying logger -
toStringStyle
protected org.apache.commons.lang3.builder.ToStringStyle toStringStyleThe style to use to turn the ident obj into a string -
identObj
The ident object to tack onto the beginning of all log messages (may be null). -
identObjStr
The stored toString of the ident object (may be null) -
identObjectIsMutable
protected boolean identObjectIsMutableSet this to true if you want the ident object to be to-stringed for each log message -
eventMarker
protected org.slf4j.Marker eventMarker -
mdcContextKV
-
DEFAULT_TO_STRING_STYLE
public static final org.apache.commons.lang3.builder.ToStringStyle DEFAULT_TO_STRING_STYLE
-
-
Constructor Details
-
LoggerEx
Deprecated.Should be replaced with calls to the builder -
LoggerEx
Deprecated.Should be replaced by using the builder.
-
-
Method Details
-
newBuilder
-
getName
-
createSubLogger
-
createSubLogger
Creates a child logger that extends from the current name, with the same identity object, event marker, and MDC context. -
setStaticMDCContextValues
A set of key/value pairs that will be set and unset in the mdc context around each logging operation. The values can change their toString value, but the keys should not. -
setEventMarker
protected void setEventMarker(org.slf4j.Marker marker) -
setIdentObject
-
getIdentObject
-
generateIdentObjStr
-
setToStringStyle
public void setToStringStyle(org.apache.commons.lang3.builder.ToStringStyle toStringStyle) -
getToStringStyle
public org.apache.commons.lang3.builder.ToStringStyle getToStringStyle() -
setIdentObjectIsMutable
public void setIdentObjectIsMutable(boolean identObjectIsMutable) -
isIdentObjectIsMutable
public boolean isIdentObjectIsMutable() -
createMessage
-
getLogger
Deprecated.Returns a Log4j logger. Calls to this function should be eliminated. -
getLoggerSLF4J
public org.slf4j.Logger getLoggerSLF4J() -
setLog
protected void setLog(org.slf4j.Logger log) -
tracef
-
tracef
-
debugf
-
debugf
-
infof
-
infof
-
warnf
-
warnf
-
errorf
-
errorf
-
fatalf
-
fatalf
-
traceEvent
Logs a trace message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are. -
debugEvent
Logs a debug message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are. -
infoEvent
Logs an info message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are. -
warnEvent
Logs a warning message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are. -
errorEvent
Logs an error message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are. -
log
@Deprecated public static void log(Class<?> clazz, LoggerEx.Level level, MDCUtils.MDCDetails mdc, String message, Object... args) Deprecated.This doesn't do anything useful and should not be used. -
mdcPut
Convenience function that calls MDC put -
mdcRemove
Convenience function that calls MDC remove -
mdcPutClosable
-
traceDuration
Duration trackers log start and finish times for operations. They return a closable and should be used in the try-with-resources style.- Parameters:
message- and identifying message for the operation. Will be used for the start and end messages.
-
debugDuration
Duration trackers log start and finish times for operations. They return a closable and should be used in the try-with-resources style.- Parameters:
message- and identifying message for the operation. Will be used for the start and end messages.
-
infoDuration
Duration trackers log start and finish times for operations. They return a closable and should be used in the try-with-resources style.- Parameters:
message- and identifying message for the operation. Will be used for the start and end messages.
-
trace
-
trace
-
debug
-
debug
-
error
-
error
-
fatal
-
fatal
-
info
-
info
-
warn
-
warn
-
isTraceEnabled
public boolean isTraceEnabled() -
isDebugEnabled
public boolean isDebugEnabled() -
isInfoEnabled
public boolean isInfoEnabled() -
mdcSet
Sets the registered mdc key/value pairs and returns a closable that can be used to unset them. It is important to note how this system works with this class: The registered key/values are set and unset for every logging operation. However, there are times when the values should stay in the context for a longer period of time, when calling into sub functions (which is more of the traditional use of mdc). In that case, this function can be used to set them. Subsequent calls to logging functions, which normally would have set and unset them, won't remove the keys- only calling close on this returned object (or mdcClose()) will unset them. -
mdcClose
public void mdcClose()The complementary function to mdcSet, if the AutoClosable return of the set function wasn't used.
-