Class Log4JWrapper


  • public class Log4JWrapper
    extends java.lang.Object
    Log4JWrapper.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Log4JWrapper​(java.lang.String name)
      Constructor for creating a logging object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addAppender​(org.apache.log4j.Appender appender)
      Adds an additional appender to logging object.
      void debug​(java.lang.Object message)
      Logs a message object with the DEBUG priority.
      void debug​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the DEBUG priority including the stack trace of the Throwable t passed as parameter.
      void debug​(java.lang.String message, java.lang.Object[] args)
      Trace a message object with the DEBUG priority, by merging the given args with the message string.
      void debugWithArgs​(java.lang.String message, java.lang.Object arg0)
      Trace a message object with the DEBUG priority, by merging the given argument with the message string.
      void debugWithArgs​(java.lang.String message, java.lang.Object arg0, java.lang.Object arg1)
      Trace a message object with the DEBUG priority, by merging the given arguments with the message string.
      void debugWithArgs​(java.lang.String message, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
      Trace a message object with the DEBUG priority, by merging the given arguments with the message string.
      void debugWithArgs​(java.lang.String message, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
      Trace a message object with the DEBUG priority, by merging the given arguments with the message string.
      void entering​(java.lang.String method)
      Traces message of severity Severity.DEBUG and appends a string denoting the name of the entered method.
      void exiting()
      Traces message of severity Severity.DEBUG which indicates that execution is about to leave this method location.
      static Log4JWrapper getInstance​(java.lang.String name)
      The method to retrieve the logging object.
      org.apache.log4j.Logger getLogger()
      This methods returns the instance of the logger.
      boolean isDebugEnabled()
      Check whether this location is enabled for the DEBUG priority.
      boolean isInfoEnabled()
      Check whether this location is enabled for the info priority.
      boolean isWarningEnabled()
      Check whether this location is enabled for the warning priority.
      void log​(int severity, LogCategory category, java.lang.String message)
      Generates a log message for the given category.
      void log​(int severity, LogCategory category, java.lang.String message, java.lang.Object[] args)
      Generates a log a message for the given severity and category by merging the given args with the message string.
      void setLevel​(org.apache.log4j.Level level)
      Sets the log level.
      void throwing​(java.lang.Throwable t)
      Should be used when an exception is thrown.
      void trace​(int severity, java.lang.String message)
      Generates a trace message for the given severity.
      void trace​(int severity, java.lang.String message, java.lang.Object[] args)
      Generates a trace message for the given severity by merging the given args with the message string.
      void traceThrowable​(int severity, java.lang.String message, java.lang.Throwable exc)
      Generates a trace message for the given severity and exception.
      void traceThrowable​(int severity, java.lang.Throwable exc, java.lang.String message, java.lang.Object[] args)
      Generates a trace message for the given severity and exception by merging the given args with the message string.
      • Methods inherited from class java.lang.Object

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

      • Log4JWrapper

        protected Log4JWrapper​(java.lang.String name)
        Constructor for creating a logging object.
        Parameters:
        name - logging object name
    • Method Detail

      • addAppender

        protected void addAppender​(org.apache.log4j.Appender appender)
        Adds an additional appender to logging object.
        Parameters:
        appender - logging appender
      • getInstance

        public static Log4JWrapper getInstance​(java.lang.String name)
        The method to retrieve the logging object. The name should contain the package name and class name.

        It will be ensured that only one instance is created

        Parameters:
        name - - the name of the current logger.
        Returns:
        the logger instance
      • log

        public void log​(int severity,
                        LogCategory category,
                        java.lang.String message)
        Generates a log message for the given category.
        Parameters:
        severity - the severity of the message
        category - the log category
        message - the message
      • log

        public void log​(int severity,
                        LogCategory category,
                        java.lang.String message,
                        java.lang.Object[] args)
        Generates a log a message for the given severity and category by merging the given args with the message string. Placeholders for the arguments in the message string must look like {i} (e.g. {0}) where i is the index in the args array.
        Parameters:
        severity - the message severity
        category - the log category
        message - the message
        args - the arguments of the message
      • trace

        public void trace​(int severity,
                          java.lang.String message)
        Generates a trace message for the given severity.
        Parameters:
        severity - the message severity
        message - the message
      • trace

        public void trace​(int severity,
                          java.lang.String message,
                          java.lang.Object[] args)
        Generates a trace message for the given severity by merging the given args with the message string. Placeholders for the arguments in the message string must look like {i} (e.g. {0}) where i is the index in the args array.
        Parameters:
        severity - the message severity
        message - the message
        args - the arguments of the message
      • traceThrowable

        public void traceThrowable​(int severity,
                                   java.lang.String message,
                                   java.lang.Throwable exc)
        Generates a trace message for the given severity and exception.
        Parameters:
        severity - the message severity
        message - the message
        exc - the exception
      • traceThrowable

        public void traceThrowable​(int severity,
                                   java.lang.Throwable exc,
                                   java.lang.String message,
                                   java.lang.Object[] args)
        Generates a trace message for the given severity and exception by merging the given args with the message string. Placeholders for the arguments in the message string must look like {i} (e.g. {0}) where i is the index in the args array.
        Parameters:
        severity - the message severity
        exc - the exception
        message - the message
        args - the arguments of the message
      • throwing

        public void throwing​(java.lang.Throwable t)
        Should be used when an exception is thrown. The exception is written using its method toString with severity Severity.ERROR.
        Parameters:
        t - an occurring exception
      • entering

        public void entering​(java.lang.String method)
        Traces message of severity Severity.DEBUG and appends a string denoting the name of the entered method. This method must be balanced with a call to exiting when leaving the traced method, for example exiting().
        Parameters:
        method - name of sublocation
      • exiting

        public void exiting()
        Traces message of severity Severity.DEBUG which indicates that execution is about to leave this method location. This method is to be balanced with a call to the method entering().
      • debug

        public void debug​(java.lang.Object message)
        Logs a message object with the DEBUG priority.
        Parameters:
        message - the message object to log using plain English.
      • debug

        public void debug​(java.lang.String message,
                          java.lang.Object[] args)
        Trace a message object with the DEBUG priority, by merging the given args with the message string. Placeholders for the arguments in the message string must look like {i} (e.g. {0}) where i is the index in the args array.
        Parameters:
        message - the message object to log using plain english.
        args - the Objects to merge with the given message.
      • debugWithArgs

        public void debugWithArgs​(java.lang.String message,
                                  java.lang.Object arg0)
        Trace a message object with the DEBUG priority, by merging the given argument with the message string. Placeholder for the argument in the message string must be {0}. This method does not require to be surrounded with an if statement to check if debug is enabled, to inhibit unnecessary memory consumption.
        Parameters:
        message - the message object to log using plain English.
        arg0 - the argument Object to merge with the given message for Placeholder {0}.
      • debugWithArgs

        public void debugWithArgs​(java.lang.String message,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1)
        Trace a message object with the DEBUG priority, by merging the given arguments with the message string. Placeholder for the argument in the message string must be {0} and {1}. This method does not require to be surrounded with an if statement to check if debug is enabled, to inhibit unnecessary memory consumption.
        Parameters:
        message - the message object to log using plain English.
        arg0 - the argument Object to merge with the given message for Placeholder {0}.
        arg1 - the argument Object to merge with the given message for Placeholder {1}.
      • debugWithArgs

        public void debugWithArgs​(java.lang.String message,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2)
        Trace a message object with the DEBUG priority, by merging the given arguments with the message string. Placeholder for the argument in the message string must be {0}, {1} and {2}. This method does not require to be surrounded with an if statement to check if debug is enabled, to inhibit unnecessary memory consumption.
        Parameters:
        message - the message object to log using plain English.
        arg0 - the argument Object to merge with the given message for Placeholder {0}.
        arg1 - the argument Object to merge with the given message for Placeholder {1}.
        arg2 - the argument Object to merge with the given message for Placeholder {2}.
      • debugWithArgs

        public void debugWithArgs​(java.lang.String message,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2,
                                  java.lang.Object arg3)
        Trace a message object with the DEBUG priority, by merging the given arguments with the message string. Placeholder for the argument in the message string must be {0}, {1}, {2} and {3}. This method does not require to be surrounded with an if statement to check if debug is enabled, to inhibit unnecessary memory consumption.
        Parameters:
        message - the message object to log using plain English.
        arg0 - the argument Object to merge with the given message for Placeholder {0}.
        arg1 - the argument Object to merge with the given message for Placeholder {1}.
        arg2 - the argument Object to merge with the given message for Placeholder {2}.
        arg3 - the argument Object to merge with the given message for Placeholder {3}.
      • debug

        public void debug​(java.lang.Object message,
                          java.lang.Throwable t)
        Log a message object with the DEBUG priority including the stack trace of the Throwable t passed as parameter.

        See debug(Object) form for more detailed information.

        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • isDebugEnabled

        public boolean isDebugEnabled()
        Check whether this location is enabled for the DEBUG priority.

        This function is intended to lessen the computational cost of disabled log debug statements.

        For some cat location object, when you write,

         cat.debug("This is entry number: " + i);
         

        You incur the cost constructing the message, concatenation in this case, regardless of whether the message is logged or not.

        If you are worried about speed, then you should write

         if (cat.isDebugEnabled())
         {
                cat.debug("This is entry number: " + i);
         }
         

        This way you will not incur the cost of parameter construction if debugging is disabled for cat. On the other hand, if the cat is debug enabled, you will incur the cost of evaluating whether the location is debug enabled twice. Once in isDebugEnabled and once in the debug. This is an insignificant overhead since evaluating a location takes about 1% of the time it takes to actually log.

        Returns:
        boolean - true if this location is debug enabled, false otherwise.
      • isInfoEnabled

        public boolean isInfoEnabled()
        Check whether this location is enabled for the info priority. See also isDebugEnabled().
        Returns:
        boolean - true if this location is enabled for priority info, false otherwise.
      • isWarningEnabled

        public boolean isWarningEnabled()
        Check whether this location is enabled for the warning priority. See also isDebugEnabled().
        Returns:
        boolean - true if this location is enabled for priority warning, false otherwise.
      • getLogger

        public org.apache.log4j.Logger getLogger()
        This methods returns the instance of the logger.
        Returns:
        the logger
      • setLevel

        public void setLevel​(org.apache.log4j.Level level)
        Sets the log level.
        Parameters:
        level - the log level