public class StandardLog extends LogContext
This class represents a specialized logging context forwarding events
to a standard logger (java.util.logging.Logger
).
This class leverages the capabilities of the standard logging facility
and extends it to support specialized logging
on a
thread or object basis. For example:
StandardLog remoteLog = new StandardLog(Logger.getLogger("remote"));
StandardLog.enter(remoteLog);
try {
StandardLog.fine("Current thread uses a remote logger");
...
} finally {
StandardLog.exit(remoteLog); // Reverts to previous logging context.
}
CONSOLE, DEFAULT, NULL, STANDARD, SYSTEM_OUT
Constructor and Description |
---|
StandardLog()
Creates a logging context forwarding events to the root logger
(
Logger.getLogger("") ). |
StandardLog(java.util.logging.Logger logger)
Creates a standard log context forwarding events to the specified
logger.
|
Modifier and Type | Method and Description |
---|---|
static void |
config(java.lang.String msg)
Logs a
CONFIG message. |
static void |
entering(java.lang.String sourceClass,
java.lang.String sourceMethod)
Log a method entry.
|
static void |
exiting(java.lang.String sourceClass,
java.lang.String sourceMethod)
Log a method return.
|
static void |
fine(java.lang.String msg)
Logs a
FINE message. |
static void |
finer(java.lang.String msg)
Logs a
FINER message. |
static void |
finest(java.lang.String msg)
Logs a
FINEST message. |
java.util.logging.Logger |
getLogger()
Returns the logger to which this context forwards the events to.
|
static boolean |
isLoggable(java.util.logging.Level level)
Checks if a message of the given level would actually be logged
by this logger.
|
protected boolean |
isLogged(java.lang.String category)
Indicates if the messages of the specified category are being logged
(default
true all messages are being logged). |
static void |
log(java.util.logging.LogRecord record)
Logs a specific LogRecord.
|
void |
logDebug(java.lang.CharSequence message)
Logs the specified debug message.
|
void |
logError(java.lang.Throwable error,
java.lang.CharSequence message)
Logs the specified error.
|
void |
logInfo(java.lang.CharSequence message)
Logs the specified informative message.
|
protected void |
logMessage(java.lang.String category,
java.lang.CharSequence message)
Logs the message of specified category (examples of category are
"debug", "info", "warning", "error").
|
void |
logWarning(java.lang.CharSequence message)
Logs the specified warning message.
|
static void |
severe(java.lang.String msg)
Logs a
SEVERE message. |
static void |
throwing(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.Throwable thrown)
Logs throwing an exception.
|
debug, debug, debug, enterAction, error, error, error, error, error, error, error, exitAction, getCurrentLogContext, getDefault, info, info, info, isDebugLogged, isErrorLogged, isInfoLogged, isWarningLogged, warning, warning, warning
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
public StandardLog()
Logger.getLogger("")
).public StandardLog(java.util.logging.Logger logger)
logger
- the logger to which log events are forwarded to.public final java.util.logging.Logger getLogger()
public static boolean isLoggable(java.util.logging.Level level)
level
- the message logging leveltrue
if a message of specified level would actually
be logged;false
otherwise.public static void log(java.util.logging.LogRecord record)
StandardLog
, an error
,
warning
, info
or debug
message is possibly logged.record
- the LogRecord to be published.public static void severe(java.lang.String msg)
SEVERE
message. If the current logging
context is not a StandardLog
a error
message is logged.msg
- the severe message.public static void config(java.lang.String msg)
CONFIG
message. If the current logging
context is not a StandardLog
no message is logged.msg
- the config message.public static void fine(java.lang.String msg)
FINE
message. If the current logging
context is not a StandardLog
no message is logged.msg
- the fine message.public static void finer(java.lang.String msg)
FINER
message. If the current logging
context is not a StandardLog
no message is logged.msg
- the finer message.public static void finest(java.lang.String msg)
FINEST
message. If the current logging
context is not a StandardLog
no message is logged.msg
- the finest message.public static void throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)
StandardLog
an error
is logged.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.thrown
- the error that is being thrown.public static void entering(java.lang.String sourceClass, java.lang.String sourceMethod)
StandardLog
a debug message is logged.sourceClass
- name of class that issued the logging request.sourceMethod
- name of method that is being entered.public static void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)
StandardLog
no return is logged.sourceClass
- name of class that issued the logging request.sourceMethod
- name of method that is being returned.protected boolean isLogged(java.lang.String category)
LogContext
true
all messages are being logged).
Note: This method is an indicator only, not a directive.
It allows users to bypass the logging processing if no
actual logging is performed. If the category is not
known then this method should return true
(no optimization performed).
isLogged
in class LogContext
category
- an identifier of the category for the messages logged.true
if the messages of the specified category
are being logged; false
otherwise.public void logDebug(java.lang.CharSequence message)
LogContext
logDebug
in class LogContext
message
- the debug message to be logged.LogContext.logMessage(java.lang.String, java.lang.CharSequence)
public void logInfo(java.lang.CharSequence message)
LogContext
logInfo
in class LogContext
message
- the informative message to be logged.public void logWarning(java.lang.CharSequence message)
LogContext
logWarning
in class LogContext
message
- the warning message to be logged.public void logError(java.lang.Throwable error, java.lang.CharSequence message)
LogContext
logMessage("", message + stackTrace)
.logError
in class LogContext
error
- the error being logged or null
if none.message
- the associated message or null
if none.protected void logMessage(java.lang.String category, java.lang.CharSequence message)
LogContext
logMessage
in class LogContext
category
- an identifier of the category of the messages logged.message
- the message itself.Copyright © 2005 - 2007 Javolution.