Class SLogger

  • All Implemented Interfaces:
    org.apache.commons.logging.Log

    public class SLogger
    extends Object
    implements org.apache.commons.logging.Log
    A wrapper around the Commons Logging Log class that supplements its features with some extras available in other logging libraries.

    Since this class itself implements Log, Beanshell should not care if you simply overwrite the ‘log’ variable in your code.

    Log strings are interpreted as Java MessageFormat objects and have the various features of that class in your JDK version.

    Values passed as arguments are only evaluated when the appropriate log level is active. If the log level is not active, the operation becomes a quick no-op. This prevents a lot of isDebugEnabled() type checks.

    The ‘S’ stands for Super. Super Logger.

    • Constructor Detail

      • SLogger

        public SLogger​(Class<?> Owner)
        Creates a new logger.
        Parameters:
        Owner - The class to log messages for.
      • SLogger

        public SLogger​(org.apache.commons.logging.Log WrapLog)
        Wraps the given log4j logger with this logger
        Parameters:
        WrapLog - The logger to wrap
      • SLogger

        public SLogger​(PrintStream Out)
        Creates a new logger.
        Parameters:
        Out - The output stream to
    • Method Detail

      • format

        public static SLogger.Formatter[] format​(Object[] args)
        Wraps the arguments for future formatting.

        The format string is not resolved at this time.

        NOTE: In newer versions of logging APIs, this would be accomplished by passing a Supplier to the API. However, in Commons Logging 1.x, this is not available. It is also not available in Beanshell, as it requires lambda syntax. If that ever becomes available, this class will become obsolete.

        Parameters:
        args - The arguments for any place-holders in the message template.
        Returns:
        The formatted arguments.
      • renderMessage

        public static String renderMessage​(String messageTemplate,
                                           Object[] args)
        Renders the MessageTemplate using the given arguments
        Parameters:
        messageTemplate - The message template
        args - The arguments
        Returns:
        The resolved message template
      • debug

        public void debug​(Object arg0)
        Specified by:
        debug in interface org.apache.commons.logging.Log
      • debug

        public void debug​(Object arg0,
                          Throwable arg1)
        Specified by:
        debug in interface org.apache.commons.logging.Log
      • debug

        public void debug​(String MessageTemplate,
                          Object... Args)
        Logs an debugging message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • error

        public void error​(Object arg0)
        Specified by:
        error in interface org.apache.commons.logging.Log
        See Also:
        Log.error(Object)
      • error

        public void error​(Object arg0,
                          Throwable arg1)
        Specified by:
        error in interface org.apache.commons.logging.Log
        See Also:
        Log.error(Object, Throwable)
      • error

        public void error​(String MessageTemplate,
                          Object... Args)
        Logs an error message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • fatal

        public void fatal​(Object arg0)
        Specified by:
        fatal in interface org.apache.commons.logging.Log
      • fatal

        public void fatal​(Object arg0,
                          Throwable arg1)
        Specified by:
        fatal in interface org.apache.commons.logging.Log
      • fatal

        public void fatal​(String MessageTemplate,
                          Object... Args)
        Logs a fatal error message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • handleException

        public void handleException​(Throwable Error)
        Handles an exception.
        Parameters:
        Error - The exception to handle.
      • info

        public void info​(Object arg0)
        Specified by:
        info in interface org.apache.commons.logging.Log
      • info

        public void info​(Object arg0,
                         Throwable arg1)
        Specified by:
        info in interface org.apache.commons.logging.Log
      • info

        public void info​(String MessageTemplate,
                         Object... Args)
        Logs an informational message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • isDebugEnabled

        public boolean isDebugEnabled()
        Specified by:
        isDebugEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isDebugEnabled()
      • isErrorEnabled

        public boolean isErrorEnabled()
        Specified by:
        isErrorEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isErrorEnabled()
      • isFatalEnabled

        public boolean isFatalEnabled()
        Specified by:
        isFatalEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isFatalEnabled()
      • isInfoEnabled

        public boolean isInfoEnabled()
        Specified by:
        isInfoEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isInfoEnabled()
      • isTraceEnabled

        public boolean isTraceEnabled()
        Specified by:
        isTraceEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isTraceEnabled()
      • isWarnEnabled

        public boolean isWarnEnabled()
        Specified by:
        isWarnEnabled in interface org.apache.commons.logging.Log
        See Also:
        Log.isWarnEnabled()
      • log

        public void log​(SLogger.Level logLevel,
                        String message)
        Logs the message at the appropriate level according to the Commons Logging API
        Parameters:
        logLevel - The log level to log at
        message - The message to log
      • save

        protected void save​(SLogger.Level LogLevel,
                            String MessageTemplate,
                            Object[] Args)
        Hook to allow log messages to be intercepted and saved.
        Parameters:
        LogLevel - The level to log the message at.
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • save

        protected void save​(Throwable Error)
        Hook to allow log messages to be intercepted and saved.

        In this version of this class, this is a no-op.

        Parameters:
        Error - The exception to handle.
      • trace

        public void trace​(Object arg0)
        Specified by:
        trace in interface org.apache.commons.logging.Log
      • trace

        public void trace​(Object arg0,
                          Throwable arg1)
        Specified by:
        trace in interface org.apache.commons.logging.Log
      • trace

        public void trace​(String MessageTemplate,
                          Object... Args)
        Logs a trace message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.
      • warn

        public void warn​(Object arg0)
        Specified by:
        warn in interface org.apache.commons.logging.Log
        See Also:
        Log.warn(Object)
      • warn

        public void warn​(Object arg0,
                         Throwable arg1)
        Specified by:
        warn in interface org.apache.commons.logging.Log
        See Also:
        Log.warn(Object, Throwable)
      • warn

        public void warn​(String MessageTemplate,
                         Object... Args)
        Logs a warning message.
        Parameters:
        MessageTemplate - A message template, which can either be a plain string or contain place-holders like {0} and {1}.
        Args - The arguments for any place-holders in the message template.