Class LoggerEx

  • Direct Known Subclasses:
    ReportExecutionContext.ReportLoggerEx

    public class LoggerEx
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static org.apache.commons.lang3.builder.ToStringStyle DEFAULT_TO_STRING_STYLE  
      protected org.slf4j.Marker eventMarker  
      protected java.lang.Object identObj
      The ident object to tack onto the beginning of all log messages (may be null).
      protected boolean identObjectIsMutable
      Set this to true if you want the ident object to be to-stringed for each log message
      protected java.lang.String identObjStr
      The stored toString of the ident object (may be null)
      protected org.slf4j.Logger log
      The underlying logger
      protected java.lang.Object[] mdcContextKV  
      protected org.apache.commons.lang3.builder.ToStringStyle toStringStyle
      The style to use to turn the ident obj into a string
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggerEx​(org.apache.log4j.Logger subLogger)
      Deprecated.
      LoggerEx​(org.apache.log4j.Logger subLogger, java.lang.Object identObj)
      Deprecated.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected java.lang.String createMessage​(java.lang.String message, java.lang.Object... args)  
      LoggerEx createSubLogger​(java.lang.Class<?> clazz)  
      LoggerEx createSubLogger​(java.lang.String name)
      Creates a child logger that extends from the current name, with the same identity object, event marker, and MDC context.
      void debug​(java.lang.String message)  
      void debug​(java.lang.String message, java.lang.Throwable t)  
      java.io.Closeable debugDuration​(java.lang.String message)
      Duration trackers log start and finish times for operations.
      void debugEvent​(java.lang.String message, java.lang.Object... args)
      Logs a debug message with the event marker defined on the logger.
      void debugf​(java.lang.String message, java.lang.Object... args)  
      void debugf​(java.lang.String message, java.lang.Object[] args, java.lang.Throwable t)  
      void error​(java.lang.String message)  
      void error​(java.lang.String message, java.lang.Throwable t)  
      void errorEvent​(java.lang.String message, java.lang.Object... args)
      Logs an error message with the event marker defined on the logger.
      void errorf​(java.lang.String message, java.lang.Object... args)  
      void errorf​(java.lang.String message, java.lang.Object[] args, java.lang.Throwable t)  
      void fatal​(java.lang.String message)  
      void fatal​(java.lang.String message, java.lang.Throwable t)  
      protected java.lang.String generateIdentObjStr()  
      java.lang.Object getIdentObject()  
      org.apache.log4j.Logger getLogger()
      Deprecated.
      org.slf4j.Logger getLoggerSLF4J()  
      java.lang.String getName()  
      org.apache.commons.lang3.builder.ToStringStyle getToStringStyle()  
      void info​(java.lang.String message)  
      void info​(java.lang.String message, java.lang.Throwable t)  
      java.io.Closeable infoDuration​(java.lang.String message)
      Duration trackers log start and finish times for operations.
      void infoEvent​(java.lang.String message, java.lang.Object... args)
      Logs an info message with the event marker defined on the logger.
      void infof​(java.lang.String message, java.lang.Object... args)  
      void infof​(java.lang.String message, java.lang.Object[] args, java.lang.Throwable t)  
      boolean isDebugEnabled()  
      boolean isIdentObjectIsMutable()  
      boolean isInfoEnabled()  
      boolean isTraceEnabled()  
      static void log​(java.lang.Class<?> clazz, LoggerEx.Level level, MDCUtils.MDCDetails mdc, java.lang.String message, java.lang.Object... args)
      Deprecated.
      void mdcClose()
      The complementary function to mdcSet, if the AutoClosable return of the set function wasn't used.
      void mdcPut​(java.lang.String key, java.lang.String value)
      Convenience function that calls MDC put
      LoggerEx.MDCClosable mdcPutClosable​(java.lang.String key, java.lang.String value)  
      void mdcRemove​(java.lang.String key)
      Convenience function that calls MDC remove
      LoggerEx.MDCClosable mdcSet()
      Sets the registered mdc key/value pairs and returns a closable that can be used to unset them.
      static LoggerEx.Builder newBuilder()  
      protected void setEventMarker​(org.slf4j.Marker marker)  
      void setIdentObject​(java.lang.Object identObj)  
      void setIdentObjectIsMutable​(boolean identObjectIsMutable)  
      protected void setLog​(org.slf4j.Logger log)  
      protected void setStaticMDCContextValues​(java.lang.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 trace​(java.lang.String message)  
      void trace​(java.lang.String message, java.lang.Throwable t)  
      java.io.Closeable traceDuration​(java.lang.String message)
      Duration trackers log start and finish times for operations.
      void traceEvent​(java.lang.String message, java.lang.Object... args)
      Logs a trace message with the event marker defined on the logger.
      void tracef​(java.lang.String message, java.lang.Object... args)  
      void tracef​(java.lang.String message, java.lang.Object[] args, java.lang.Throwable t)  
      void warn​(java.lang.String message)  
      void warn​(java.lang.String message, java.lang.Throwable t)  
      void warnEvent​(java.lang.String message, java.lang.Object... args)
      Logs a warning message with the event marker defined on the logger.
      void warnf​(java.lang.String message, java.lang.Object... args)  
      void warnf​(java.lang.String message, java.lang.Object[] args, java.lang.Throwable t)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 java.lang.Object identObj
        The ident object to tack onto the beginning of all log messages (may be null).
      • identObjStr

        protected java.lang.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 java.lang.Object[] mdcContextKV
      • DEFAULT_TO_STRING_STYLE

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

      • 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,
                        java.lang.Object identObj)
        Deprecated.
        Should be replaced by using the builder.
    • Method Detail

      • getName

        public java.lang.String getName()
      • createSubLogger

        public LoggerEx createSubLogger​(java.lang.Class<?> clazz)
      • createSubLogger

        public LoggerEx createSubLogger​(java.lang.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​(java.lang.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​(java.lang.Object identObj)
      • getIdentObject

        public java.lang.Object getIdentObject()
      • generateIdentObjStr

        protected java.lang.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 java.lang.String createMessage​(java.lang.String message,
                                                 java.lang.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​(java.lang.String message,
                           java.lang.Object... args)
      • tracef

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

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

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

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

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

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

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

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

        public void errorf​(java.lang.String message,
                           java.lang.Object[] args,
                           java.lang.Throwable t)
      • traceEvent

        public void traceEvent​(java.lang.String message,
                               java.lang.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​(java.lang.String message,
                               java.lang.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​(java.lang.String message,
                              java.lang.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​(java.lang.String message,
                              java.lang.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​(java.lang.String message,
                               java.lang.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​(java.lang.Class<?> clazz,
                               LoggerEx.Level level,
                               MDCUtils.MDCDetails mdc,
                               java.lang.String message,
                               java.lang.Object... args)
        Deprecated.
        This doesn't do anything useful and should not be used.
      • mdcPut

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

        public void mdcRemove​(java.lang.String key)
        Convenience function that calls MDC remove
      • mdcPutClosable

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

        public java.io.Closeable traceDuration​(java.lang.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 java.io.Closeable debugDuration​(java.lang.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 java.io.Closeable infoDuration​(java.lang.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​(java.lang.String message)
      • trace

        public void trace​(java.lang.String message,
                          java.lang.Throwable t)
      • debug

        public void debug​(java.lang.String message)
      • debug

        public void debug​(java.lang.String message,
                          java.lang.Throwable t)
      • error

        public void error​(java.lang.String message)
      • error

        public void error​(java.lang.String message,
                          java.lang.Throwable t)
      • fatal

        public void fatal​(java.lang.String message)
      • fatal

        public void fatal​(java.lang.String message,
                          java.lang.Throwable t)
      • info

        public void info​(java.lang.String message)
      • info

        public void info​(java.lang.String message,
                         java.lang.Throwable t)
      • warn

        public void warn​(java.lang.String message)
      • warn

        public void warn​(java.lang.String message,
                         java.lang.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.