java.lang.Object
com.inductiveautomation.ignition.common.util.LoggerEx
Direct Known Subclasses:
ReportExecutionContext.ReportLoggerEx

public class LoggerEx extends Object
This class is a wrapper around a logger which provides additional useful tools. To create one, use the newBuilder() function and configure the builder.
  • Field Details

    • log

      protected org.slf4j.Logger log
      The underlying logger
    • toStringStyle

      protected org.apache.commons.lang3.builder.ToStringStyle toStringStyle
      The style to use to turn the ident obj into a string
    • identObj

      protected Object identObj
      The ident object to tack onto the beginning of all log messages (may be null).
    • identObjStr

      protected String identObjStr
      The stored toString of the ident object (may be null)
    • identObjectIsMutable

      protected boolean identObjectIsMutable
      Set this to true if you want the ident object to be to-stringed for each log message
    • eventMarker

      protected org.slf4j.Marker eventMarker
    • mdcContextKV

      protected Object[] mdcContextKV
    • DEFAULT_TO_STRING_STYLE

      public static final org.apache.commons.lang3.builder.ToStringStyle DEFAULT_TO_STRING_STYLE
  • Constructor Details

    • LoggerEx

      @Deprecated public LoggerEx(org.apache.log4j.Logger subLogger)
      Deprecated.
      Should be replaced with calls to the builder
    • LoggerEx

      @Deprecated public LoggerEx(org.apache.log4j.Logger subLogger, Object identObj)
      Deprecated.
      Should be replaced by using the builder.
  • Method Details

    • newBuilder

      public static LoggerEx.Builder newBuilder()
    • getName

      public String getName()
    • createSubLogger

      public LoggerEx createSubLogger(Class<?> clazz)
    • createSubLogger

      public LoggerEx createSubLogger(String name)
      Creates a child logger that extends from the current name, with the same identity object, event marker, and MDC context.
    • setStaticMDCContextValues

      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. The values can change their toString value, but the keys should not.
    • setEventMarker

      protected void setEventMarker(org.slf4j.Marker marker)
    • setIdentObject

      public void setIdentObject(Object identObj)
    • getIdentObject

      public Object getIdentObject()
    • generateIdentObjStr

      protected String 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

      protected String createMessage(String message, Object... args)
    • getLogger

      @Deprecated public org.apache.log4j.Logger 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

      public void tracef(String message, Object... args)
    • tracef

      public void tracef(String message, Object[] args, Throwable t)
    • debugf

      public void debugf(String message, Object... args)
    • debugf

      public void debugf(String message, Object[] args, Throwable t)
    • infof

      public void infof(String message, Object... args)
    • infof

      public void infof(String message, Object[] args, Throwable t)
    • warnf

      public void warnf(String message, Object... args)
    • warnf

      public void warnf(String message, Object[] args, Throwable t)
    • errorf

      public void errorf(String message, Object... args)
    • errorf

      public void errorf(String message, Object[] args, Throwable t)
    • fatalf

      public void fatalf(String message, Object... args)
    • fatalf

      public void fatalf(String message, Object[] args, Throwable t)
    • traceEvent

      public void traceEvent(String message, Object... args)
      Logs a trace message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are.
    • debugEvent

      public void debugEvent(String message, Object... args)
      Logs a debug message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are.
    • infoEvent

      public void infoEvent(String message, Object... args)
      Logs an info message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are.
    • warnEvent

      public void warnEvent(String message, Object... args)
      Logs a warning message with the event marker defined on the logger. See Builder.eventSystem for more information about what events are.
    • errorEvent

      public void errorEvent(String message, Object... args)
      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

      public void mdcPut(String key, String value)
      Convenience function that calls MDC put
    • mdcRemove

      public void mdcRemove(String key)
      Convenience function that calls MDC remove
    • mdcPutClosable

      public LoggerEx.MDCClosable mdcPutClosable(String key, String value)
    • traceDuration

      public Closeable traceDuration(String message)
      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

      public Closeable debugDuration(String message)
      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

      public Closeable infoDuration(String message)
      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

      public void trace(String message)
    • trace

      public void trace(String message, Throwable t)
    • debug

      public void debug(String message)
    • debug

      public void debug(String message, Throwable t)
    • error

      public void error(String message)
    • error

      public void error(String message, Throwable t)
    • fatal

      public void fatal(String message)
    • fatal

      public void fatal(String message, Throwable t)
    • info

      public void info(String message)
    • info

      public void info(String message, Throwable t)
    • warn

      public void warn(String message)
    • warn

      public void warn(String message, Throwable t)
    • isTraceEnabled

      public boolean isTraceEnabled()
    • isDebugEnabled

      public boolean isDebugEnabled()
    • isInfoEnabled

      public boolean isInfoEnabled()
    • mdcSet

      public LoggerEx.MDCClosable 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.