@InterfaceAudience.Public @InterfaceStability.Evolving public class Logger extends Object implements Shutdownable
Logger
class to log the Application specific messages. Is not based on
log4j (to reduce external dependencies).
However, if needed, something like log4j could easily be hooked in.Log| Modifier and Type | Method and Description |
|---|---|
void |
debug(Object message)
Log a message object with the
DEBUG level. |
void |
debug(Object message,
Throwable t)
Log a message object with the
DEBUG level including
the stack trace of the Throwable t passed as
parameter. |
void |
error(Object message)
Log a message object with the
ERROR Level.. |
void |
error(Object message,
Throwable t)
Log a message object with the
ERROR level including the
stack trace of the Throwable t passed as parameter. |
void |
fatal(Object message)
Log a message object with the
FATAL Level. |
void |
fatal(Object message,
Throwable t)
Log a message object with the
FATAL level including
the stack trace of the Throwable t passed as
parameter. |
MyLogLevel |
getLevel()
Returns the assigned
MyLogLevel, if any, for this Category. |
static Logger |
getLogger(Class<?> klass)
Retrieve a logger named according to the value of the
name
parameter. |
static Logger |
getLogger(String name)
Retrieve a logger named according to the value of the
name
parameter. |
String |
getName()
Gets the name.
|
void |
info(Object message)
Log a message object with the
INFO Level. |
void |
info(Object message,
Throwable t)
Log a message object with the
INFO level including the
stack trace of the Throwable t passed as parameter. |
boolean |
isDebugEnabled()
Check whether this category is enabled for the
DEBUG Level. |
boolean |
isInfoEnabled()
Check whether this category is enabled for the info Level.
|
void |
log(Object message,
int level,
String levelString)
Log a message object with the
MyLevel (an user
defined) Level. |
void |
log(Object message,
Throwable t)
Log a message object with the
MyLevel (an user
defined) Level including the stack trace of the Throwable t passed
as parameter. |
void |
setLevel(MyLogLevel level)
Set the level of this Category.
|
void |
shutdown(ShutdownMode mode)
Shutdowns this entity properly by performing all the necessary steps to
make sure that all the used resources are released properly based on the
ShutdownMode specified. |
void |
test(Object message)
Log a message object with the test Level.
|
void |
test(Object message,
Throwable t)
Log a message object with the test level including the
stack trace of the
Throwable t passed as parameter. |
String |
toString() |
void |
trace(Object message)
Log a message object with the
TRACE level. |
void |
trace(Object message,
Throwable t)
Log a message object with the
TRACE level including
the stack trace of the Throwablet passed as
parameter. |
void |
warn(Object message)
Log a message object with the
WARN Level. |
void |
warn(Object message,
Throwable t)
|
public static Logger getLogger(Class<?> klass)
name
parameter. If the named logger already exists, then the existing instance
will be returned. Otherwise, a new instance is created.klass - the klasspublic static Logger getLogger(String name)
name
parameter. If the named logger already exists, then the existing instance
will be returned. Otherwise, a new instance is created.name - the namepublic String getName()
public void trace(Object message)
TRACE level.message - the messagepublic void trace(Object message, Throwable t)
TRACE level including
the stack trace of the Throwablet passed as
parameter.
See debug(Object) form for more detailed information.
message - the messaget - the tpublic void info(Object message)
INFO Level.message - the messagepublic void info(Object message, Throwable t)
INFO level including the
stack trace of the Throwable t passed as parameter.
See info(Object) for more detailed information.
message - the messaget - the tpublic void debug(Object message)
DEBUG level.message - the messagepublic void debug(Object message, Throwable t)
DEBUG level including
the stack trace of the Throwable t passed as
parameter.
message - the messaget - the tform for more detailed information.public void warn(Object message)
WARN Level.message - the messagepublic void warn(Object message, Throwable t)
message - the messaget - the tfor more detailed information.public void error(Object message)
ERROR Level..message - the messagepublic void error(Object message, Throwable t)
ERROR level including the
stack trace of the Throwable t passed as parameter.message - the messaget - the tform for more detailed information.public void fatal(Object message)
FATAL Level.message - the messagepublic void fatal(Object message, Throwable t)
FATAL level including
the stack trace of the Throwable t passed as
parameter.message - the messaget - the tfor more detailed information.public void test(Object message)
DEBUG andmessage - the message INFO are not adequate.public void test(Object message, Throwable t)
Throwable t passed as parameter.message - the messaget - the tfor more detailed information.public void log(Object message, int level, String levelString)
MyLevel (an user
defined) Level. message - the messagelevel - the levellevelString - the level stringpublic void log(Object message, Throwable t)
MyLevel (an user
defined) Level Throwable t passed
as parameter.message - the messaget - the tfor more detailed information.public boolean isDebugEnabled()
DEBUG Level.
This function is intended to lessen the computational cost of disabled log debug statements.
For some cat Category object, when you write,
logger.debug("This is entry number: " + i);
You incur the cost constructing the message, concatenatiion in this case, regardless of whether the message is logged or not.
If you are worried about speed, then you should write
if (logger.isDebugEnabled())
{
logger.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 category is debug enabled twice. Once in
isDebugEnabled and once in the debug. This is
an insignificant overhead since evaluating a category takes about 1%% of
the time it takes to actually log.
true if this category is debug enabled,
false otherwise.public boolean isInfoEnabled()
isDebugEnabled().true if this category is enabled for level
info, false otherwise.public void setLevel(MyLogLevel level)
MyLogLevel.DEBUG, MyLogLevel.INFO,
MyLogLevel.WARN, MyLogLevel.ERROR,
MyLogLevel.FATAL as a parameter, you need to case them as
MyLogLevel.
As in
logger.setLevel((MyLogLevel) MyLogLevel.DEBUG);Null values are not entertained.
level - the new levelpublic MyLogLevel getLevel()
MyLogLevel, if any, for this Category.null. the
levelpublic void shutdown(ShutdownMode mode)
ShutdownableShutdownMode specified.shutdown in interface Shutdownablemode - the modeCopyright © 2016 utils4j. All Rights Reserved.