Class SLogger
- java.lang.Object
-
- com.identityworksllc.iiq.common.logging.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 LoggingLog
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SLogger.Formatter
Helper class to format an object for logging.static class
SLogger.Level
An enumeration of log levels to replace the one in log4j
-
Constructor Summary
Constructors Constructor Description SLogger(PrintStream Out)
Creates a new logger.SLogger(Class<?> Owner)
Creates a new logger.SLogger(org.apache.commons.logging.Log WrapLog)
Wraps the given log4j logger with this logger
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
debug(Object arg0)
void
debug(Object arg0, Throwable arg1)
void
debug(String MessageTemplate, Object... Args)
Logs an debugging message.void
error(Object arg0)
void
error(Object arg0, Throwable arg1)
void
error(String MessageTemplate, Object... Args)
Logs an error message.void
fatal(Object arg0)
void
fatal(Object arg0, Throwable arg1)
void
fatal(String MessageTemplate, Object... Args)
Logs a fatal error message.static SLogger.Formatter[]
format(Object[] args)
Wraps the arguments for future formatting.void
handleException(Throwable Error)
Handles an exception.void
info(Object arg0)
void
info(Object arg0, Throwable arg1)
void
info(String MessageTemplate, Object... Args)
Logs an informational message.boolean
isDebugEnabled()
boolean
isErrorEnabled()
boolean
isFatalEnabled()
boolean
isInfoEnabled()
boolean
isTraceEnabled()
boolean
isWarnEnabled()
void
log(SLogger.Level logLevel, String message)
Logs the message at the appropriate level according to the Commons Logging APIstatic String
renderMessage(String messageTemplate, Object[] args)
Renders the MessageTemplate using the given argumentsprotected void
save(SLogger.Level LogLevel, String MessageTemplate, Object[] Args)
Hook to allow log messages to be intercepted and saved.protected void
save(Throwable Error)
Hook to allow log messages to be intercepted and saved.void
trace(Object arg0)
void
trace(Object arg0, Throwable arg1)
void
trace(String MessageTemplate, Object... Args)
Logs a trace message.void
warn(Object arg0)
void
warn(Object arg0, Throwable arg1)
void
warn(String MessageTemplate, Object... Args)
Logs a warning message.
-
-
-
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 templateargs
- The arguments- Returns:
- The resolved message template
-
debug
public void debug(Object arg0)
- Specified by:
debug
in interfaceorg.apache.commons.logging.Log
-
debug
public void debug(Object arg0, Throwable arg1)
- Specified by:
debug
in interfaceorg.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 interfaceorg.apache.commons.logging.Log
- See Also:
Log.error(Object)
-
error
public void error(Object arg0, Throwable arg1)
- Specified by:
error
in interfaceorg.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 interfaceorg.apache.commons.logging.Log
-
fatal
public void fatal(Object arg0, Throwable arg1)
- Specified by:
fatal
in interfaceorg.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, Throwable arg1)
- Specified by:
info
in interfaceorg.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 interfaceorg.apache.commons.logging.Log
- See Also:
Log.isDebugEnabled()
-
isErrorEnabled
public boolean isErrorEnabled()
- Specified by:
isErrorEnabled
in interfaceorg.apache.commons.logging.Log
- See Also:
Log.isErrorEnabled()
-
isFatalEnabled
public boolean isFatalEnabled()
- Specified by:
isFatalEnabled
in interfaceorg.apache.commons.logging.Log
- See Also:
Log.isFatalEnabled()
-
isInfoEnabled
public boolean isInfoEnabled()
- Specified by:
isInfoEnabled
in interfaceorg.apache.commons.logging.Log
- See Also:
Log.isInfoEnabled()
-
isTraceEnabled
public boolean isTraceEnabled()
- Specified by:
isTraceEnabled
in interfaceorg.apache.commons.logging.Log
- See Also:
Log.isTraceEnabled()
-
isWarnEnabled
public boolean isWarnEnabled()
- Specified by:
isWarnEnabled
in interfaceorg.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 atmessage
- 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 interfaceorg.apache.commons.logging.Log
-
trace
public void trace(Object arg0, Throwable arg1)
- Specified by:
trace
in interfaceorg.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 interfaceorg.apache.commons.logging.Log
- See Also:
Log.warn(Object)
-
warn
public void warn(Object arg0, Throwable arg1)
- Specified by:
warn
in interfaceorg.apache.commons.logging.Log
- See Also:
Log.warn(Object, Throwable)
-
-