Package org.owasp.esapi.reference
Class Log4JLogger
- java.lang.Object
-
- org.apache.log4j.Category
-
- org.apache.log4j.Logger
-
- org.owasp.esapi.reference.Log4JLogger
-
- All Implemented Interfaces:
org.apache.log4j.spi.AppenderAttachable
,Logger
public class Log4JLogger extends org.apache.log4j.Logger implements Logger
Reference implementation of the Logger interface. This implementation extends org.apache.log4j.Logger in order to take advantage of per-class and per-package configuration options provided by Log4J.- Since:
- October 15, 2010
- Author:
- August Detlefsen (augustd at codemagi dot com) CodeMagi, Inc.
- See Also:
Log4JLogFactory
,Log4JLoggerFactory
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.owasp.esapi.Logger
Logger.EventType
-
-
Field Summary
-
Fields inherited from class org.apache.log4j.Category
additive, level, name, parent, repository, resourceBundle
-
Fields inherited from interface org.owasp.esapi.Logger
ALL, DEBUG, ERROR, EVENT_FAILURE, EVENT_SUCCESS, EVENT_UNSPECIFIED, FATAL, INFO, OFF, SECURITY_AUDIT, SECURITY_FAILURE, SECURITY_SUCCESS, TRACE, WARNING
-
-
Constructor Summary
Constructors Constructor Description Log4JLogger(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
always(java.lang.Object message)
Always log the specified message as aSECURITY_AUDIT
event type.void
always(java.lang.Object message, java.lang.Throwable throwable)
Always log the specified message as aSECURITY_AUDIT
event type, along with its associated exception stack trace (if any).void
always(Logger.EventType type, java.lang.String message)
Log an event regardless of what logging level is enabled.void
always(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an event regardless of what logging level is enabled and also record the stack trace associated with the event.void
debug(java.lang.Object message)
void
debug(java.lang.Object message, java.lang.Throwable throwable)
void
debug(Logger.EventType type, java.lang.String message)
Log a debug level security event if 'debug' level logging is enabled.void
debug(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a debug level security event if 'debug' level logging is enabled and also record the stack trace associated with the event.void
error(java.lang.Object message)
void
error(java.lang.Object message, java.lang.Throwable throwable)
void
error(Logger.EventType type, java.lang.String message)
Log an error level security event if 'error' level logging is enabled.void
error(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an error level security event if 'error' level logging is enabled and also record the stack trace associated with the event.void
fatal(java.lang.Object message)
void
fatal(java.lang.Object message, java.lang.Throwable throwable)
void
fatal(Logger.EventType type, java.lang.String message)
Log a fatal event if 'fatal' level logging is enabled.void
fatal(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a fatal level security event if 'fatal' level logging is enabled and also record the stack trace associated with the event.int
getESAPILevel()
Retrieve the current ESAPI logging level for this logger.static org.apache.log4j.Category
getInstance(java.lang.Class clazz)
This method overridesCategory.getInstance(java.lang.String)
by supplying its own factory type as a parameter.static org.apache.log4j.Category
getInstance(java.lang.String name)
This method overridesCategory.getInstance(java.lang.String)
by supplying its own factory type as a parameter.static org.apache.log4j.Logger
getLogger(java.lang.Class clazz)
This method overridesLogger.getLogger(java.lang.String)
by supplying its own factory type as a parameter.static org.apache.log4j.Logger
getLogger(java.lang.String name)
This method overridesLogger.getLogger(java.lang.String)
by supplying its own factory type as a parameter.java.lang.String
getUserInfo()
void
info(java.lang.Object message)
void
info(java.lang.Object message, java.lang.Throwable throwable)
void
info(Logger.EventType type, java.lang.String message)
Log an info level security event if 'info' level logging is enabled.void
info(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an info level security event if 'info' level logging is enabled and also record the stack trace associated with the event.boolean
isDebugEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.boolean
isErrorEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.boolean
isFatalEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.boolean
isInfoEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.boolean
isTraceEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.boolean
isWarningEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.void
setLevel(int level)
Dynamically set the ESAPI logging severity level.void
trace(java.lang.Object message)
void
trace(java.lang.Object message, java.lang.Throwable throwable)
void
trace(Logger.EventType type, java.lang.String message)
Log a trace level security event if 'trace' level logging is enabled.void
trace(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a trace level security event if 'trace' level logging is enabled and also record the stack trace associated with the event.void
warn(java.lang.Object message)
void
warn(java.lang.Object message, java.lang.Throwable throwable)
void
warning(Logger.EventType type, java.lang.String message)
Log a warning level security event if 'warning' level logging is enabled.void
warning(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a warning level security event if 'warning' level logging is enabled and also record the stack trace associated with the event.-
Methods inherited from class org.apache.log4j.Category
addAppender, assertLog, callAppenders, exists, forcedLog, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getEffectiveLevel, getHierarchy, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundle, getResourceBundleString, getRoot, isAttached, isEnabledFor, l7dlog, l7dlog, log, log, log, removeAllAppenders, removeAppender, removeAppender, setAdditivity, setLevel, setPriority, setResourceBundle, shutdown
-
-
-
-
Method Detail
-
getInstance
public static org.apache.log4j.Category getInstance(java.lang.String name)
This method overridesCategory.getInstance(java.lang.String)
by supplying its own factory type as a parameter.
-
getInstance
public static org.apache.log4j.Category getInstance(java.lang.Class clazz)
This method overridesCategory.getInstance(java.lang.String)
by supplying its own factory type as a parameter.
-
getLogger
public static org.apache.log4j.Logger getLogger(java.lang.String name)
This method overridesLogger.getLogger(java.lang.String)
by supplying its own factory type as a parameter.
-
getLogger
public static org.apache.log4j.Logger getLogger(java.lang.Class clazz)
This method overridesLogger.getLogger(java.lang.String)
by supplying its own factory type as a parameter.
-
setLevel
public void setLevel(int level)
Dynamically set the ESAPI logging severity level. All events of this level and higher will be logged from this point forward for all logs. All events below this level will be discarded. Note: In this implementation, this change is not persistent, meaning that if the application is restarted, the log level will revert to the level defined in the ESAPI SecurityConfiguration properties file.
-
getESAPILevel
public int getESAPILevel()
Retrieve the current ESAPI logging level for this logger. SeeLog4JLogger
for an explanation of why this method is not simply calledgetLevel()
. Explanation: Since this class extends Log4j's Logger class which has agetLevel()
method that returnsextended by org.apache.log4j.Level
, we can't simply have agetLevel()
that simply returns anint
. Hence we renamed it togetESAPILevel()
.- Specified by:
getESAPILevel
in interfaceLogger
- Returns:
- The current logging level.
-
always
public void always(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an event regardless of what logging level is enabled and also record the stack trace associated with the event.
-
always
public void always(Logger.EventType type, java.lang.String message)
Log an event regardless of what logging level is enabled.
-
trace
public void trace(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a trace level security event if 'trace' level logging is enabled and also record the stack trace associated with the event.
-
trace
public void trace(Logger.EventType type, java.lang.String message)
Log a trace level security event if 'trace' level logging is enabled.
-
debug
public void debug(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a debug level security event if 'debug' level logging is enabled and also record the stack trace associated with the event.
-
debug
public void debug(Logger.EventType type, java.lang.String message)
Log a debug level security event if 'debug' level logging is enabled.
-
info
public void info(Logger.EventType type, java.lang.String message)
Log an info level security event if 'info' level logging is enabled.
-
info
public void info(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an info level security event if 'info' level logging is enabled and also record the stack trace associated with the event.
-
warning
public void warning(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a warning level security event if 'warning' level logging is enabled and also record the stack trace associated with the event.
-
warning
public void warning(Logger.EventType type, java.lang.String message)
Log a warning level security event if 'warning' level logging is enabled.
-
error
public void error(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log an error level security event if 'error' level logging is enabled and also record the stack trace associated with the event.
-
error
public void error(Logger.EventType type, java.lang.String message)
Log an error level security event if 'error' level logging is enabled.
-
fatal
public void fatal(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)
Log a fatal level security event if 'fatal' level logging is enabled and also record the stack trace associated with the event.
-
fatal
public void fatal(Logger.EventType type, java.lang.String message)
Log a fatal event if 'fatal' level logging is enabled.
-
always
public void always(java.lang.Object message)
Always log the specified message as aSECURITY_AUDIT
event type.- Parameters:
message
- TheString
representation of the specified message as logged by calling the object'stoString()
method.
-
always
public void always(java.lang.Object message, java.lang.Throwable throwable)
Always log the specified message as aSECURITY_AUDIT
event type, along with its associated exception stack trace (if any).- Parameters:
message
- TheString
representation of the specified message as logged by calling the object'stoString()
method.
-
trace
public void trace(java.lang.Object message)
- Overrides:
trace
in classorg.apache.log4j.Logger
-
trace
public void trace(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
trace
in classorg.apache.log4j.Logger
-
debug
public void debug(java.lang.Object message)
- Overrides:
debug
in classorg.apache.log4j.Category
-
debug
public void debug(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
debug
in classorg.apache.log4j.Category
-
info
public void info(java.lang.Object message)
- Overrides:
info
in classorg.apache.log4j.Category
-
info
public void info(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
info
in classorg.apache.log4j.Category
-
warn
public void warn(java.lang.Object message)
- Overrides:
warn
in classorg.apache.log4j.Category
-
warn
public void warn(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
warn
in classorg.apache.log4j.Category
-
error
public void error(java.lang.Object message)
- Overrides:
error
in classorg.apache.log4j.Category
-
error
public void error(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
error
in classorg.apache.log4j.Category
-
fatal
public void fatal(java.lang.Object message)
- Overrides:
fatal
in classorg.apache.log4j.Category
-
fatal
public void fatal(java.lang.Object message, java.lang.Throwable throwable)
- Overrides:
fatal
in classorg.apache.log4j.Category
-
isDebugEnabled
public boolean isDebugEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isDebugEnabled
in interfaceLogger
- Overrides:
isDebugEnabled
in classorg.apache.log4j.Category
- Returns:
- true if debug level messages will be output to the log
-
isErrorEnabled
public boolean isErrorEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isErrorEnabled
in interfaceLogger
- Returns:
- true if error level messages will be output to the log
-
isFatalEnabled
public boolean isFatalEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isFatalEnabled
in interfaceLogger
- Returns:
- true if fatal level messages will be output to the log
-
isInfoEnabled
public boolean isInfoEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isInfoEnabled
in interfaceLogger
- Overrides:
isInfoEnabled
in classorg.apache.log4j.Category
- Returns:
- true if info level messages will be output to the log
-
isTraceEnabled
public boolean isTraceEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isTraceEnabled
in interfaceLogger
- Overrides:
isTraceEnabled
in classorg.apache.log4j.Logger
- Returns:
- true if trace level messages will be output to the log
-
isWarningEnabled
public boolean isWarningEnabled()
Allows the caller to determine if messages logged at this level will be discarded, to avoid performing expensive processing.- Specified by:
isWarningEnabled
in interfaceLogger
- Returns:
- true if warning level messages will be output to the log
-
getUserInfo
public java.lang.String getUserInfo()
-
-