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 class
protected class
protected class
protected static enum
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.commons.lang3.builder.ToStringStyle
protected org.slf4j.Marker
protected Object
The ident object to tack onto the beginning of all log messages (may be null).protected boolean
Set this to true if you want the ident object to be to-stringed for each log messageprotected String
The stored toString of the ident object (may be null)protected org.slf4j.Logger
The underlying loggerprotected Object[]
protected org.apache.commons.lang3.builder.ToStringStyle
The style to use to turn the ident obj into a string -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
createMessage
(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.void
void
debugDuration
(String message) Duration trackers log start and finish times for operations.void
debugEvent
(String message, Object... args) Logs a debug message with the event marker defined on the logger.void
void
void
void
void
errorEvent
(String message, Object... args) Logs an error message with the event marker defined on the logger.void
void
void
void
void
void
protected String
org.apache.log4j.Logger
Deprecated.org.slf4j.Logger
getName()
org.apache.commons.lang3.builder.ToStringStyle
void
void
infoDuration
(String message) Duration trackers log start and finish times for operations.void
Logs an info message with the event marker defined on the logger.void
void
boolean
boolean
boolean
boolean
static void
log
(Class<?> clazz, LoggerEx.Level level, MDCUtils.MDCDetails mdc, String message, Object... args) Deprecated.void
mdcClose()
The complementary function to mdcSet, if the AutoClosable return of the set function wasn't used.void
Convenience function that calls MDC putmdcPutClosable
(String key, String value) void
Convenience 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.Builder
protected void
setEventMarker
(org.slf4j.Marker marker) void
setIdentObject
(Object identObj) void
setIdentObjectIsMutable
(boolean identObjectIsMutable) protected void
setLog
(org.slf4j.Logger log) protected void
setStaticMDCContextValues
(Object... values) A set of key/value pairs that will be set and unset in the mdc context around each logging operation.void
setToStringStyle
(org.apache.commons.lang3.builder.ToStringStyle toStringStyle) void
void
traceDuration
(String message) Duration trackers log start and finish times for operations.void
traceEvent
(String message, Object... args) Logs a trace message with the event marker defined on the logger.void
void
void
void
void
Logs a warning message with the event marker defined on the logger.void
void
-
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.
-