Class Log4JWrapper
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLog4JWrapper(String name) Constructor for creating a logging object. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAppender(org.apache.log4j.Appender appender) Adds an additional appender to logging object.voidLogs a message object with theDEBUGpriority.voidLog a message object with theDEBUGpriority including the stack trace of theThrowabletpassed as parameter.voidTrace a message object with theDEBUGpriority, by merging the given args with the message string.voiddebugWithArgs(String message, Object arg0) Trace a message object with theDEBUGpriority, by merging the given argument with the message string.voiddebugWithArgs(String message, Object arg0, Object arg1) Trace a message object with theDEBUGpriority, by merging the given arguments with the message string.voiddebugWithArgs(String message, Object arg0, Object arg1, Object arg2) Trace a message object with theDEBUGpriority, by merging the given arguments with the message string.voidTrace a message object with theDEBUGpriority, by merging the given arguments with the message string.voidTraces message of severity Severity.DEBUG and appends a string denoting the name of the entered method.voidexiting()Traces message of severity Severity.DEBUG which indicates that execution is about to leave this method location.static Log4JWrappergetInstance(String name) The method to retrieve the logging object.org.apache.log4j.LoggerThis methods returns the instance of the logger.booleanCheck whether this location is enabled for theDEBUGpriority.booleanCheck whether this location is enabled for the info priority.booleanCheck whether this location is enabled for the warning priority.voidlog(int severity, LogCategory category, String message) Generates a log message for the given category.voidlog(int severity, LogCategory category, String message, Object[] args) Generates a log a message for the given severity and category by merging the given args with the message string.voidsetLevel(org.apache.log4j.Level level) Sets the log level.voidShould be used when an exception is thrown.voidGenerates a trace message for the given severity.voidGenerates a trace message for the given severity by merging the given args with the message string.voidtraceThrowable(int severity, String message, Throwable exc) Generates a trace message for the given severity and exception.voidtraceThrowable(int severity, Throwable exc, String message, Object[] args) Generates a trace message for the given severity and exception by merging the given args with the message string.
-
Constructor Details
-
Log4JWrapper
Constructor for creating a logging object.- Parameters:
name- logging object name
-
-
Method Details
-
addAppender
protected void addAppender(org.apache.log4j.Appender appender) Adds an additional appender to logging object.- Parameters:
appender- logging appender
-
getInstance
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
Generates a log message for the given category.- Parameters:
severity- the severity of the messagecategory- the log categorymessage- the message
-
log
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 severitycategory- the log categorymessage- the messageargs- the arguments of the message
-
trace
Generates a trace message for the given severity.- Parameters:
severity- the message severitymessage- the message
-
trace
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 severitymessage- the messageargs- the arguments of the message
-
traceThrowable
Generates a trace message for the given severity and exception.- Parameters:
severity- the message severitymessage- the messageexc- the exception
-
traceThrowable
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 severityexc- the exceptionmessage- the messageargs- the arguments of the message
-
throwing
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
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
Logs a message object with theDEBUGpriority.- Parameters:
message- the message object to log using plain English.
-
debug
Trace a message object with theDEBUGpriority, 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
Trace a message object with theDEBUGpriority, 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
Trace a message object with theDEBUGpriority, 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
Trace a message object with theDEBUGpriority, 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
Trace a message object with theDEBUGpriority, 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
Log a message object with theDEBUGpriority including the stack trace of theThrowabletpassed 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 theDEBUGpriority.This function is intended to lessen the computational cost of disabled log debug statements.
For some
catlocation 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 thecatis debug enabled, you will incur the cost of evaluating whether the location is debug enabled twice. Once inisDebugEnabledand once in thedebug. This is an insignificant overhead since evaluating a location takes about 1% of the time it takes to actually log.- Returns:
- boolean -
trueif this location is debug enabled,falseotherwise.
-
isInfoEnabled
public boolean isInfoEnabled()Check whether this location is enabled for the info priority. See alsoisDebugEnabled().- Returns:
- boolean -
trueif this location is enabled for priority info,falseotherwise.
-
isWarningEnabled
public boolean isWarningEnabled()Check whether this location is enabled for the warning priority. See alsoisDebugEnabled().- Returns:
- boolean -
trueif this location is enabled for priority warning,falseotherwise.
-
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
-