|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.realtime.Context
javolution.realtime.LogContext
public abstract class LogContext
This class represents a logging context; it allows for
object-based/thread-based logging and logging specializations
(such as StandardLog to leverage
java.util.logging capabilities).
The default logging context is STANDARD (log events forwarded
to the root java.util.logging.Logger). Users may
changes the default logging for all threads:
and/or perform custom logging for particular objects/threads:
// Logging disabled by default.
LogContext.setDefault(LogContext.NULL);
LogContext.enter(LogContext.SYSTEM);
try {
LogContext.info("Writes this message to System.out");
...
} finally {
LogContext.exit(LogContext.SYSTEM);
}
Applications may extend this base class to address specific logging
requirements. For example:
// This class allows for custom logging of session events.
public abstract class SessionLog extends LogContext {
public static void start(Session session) {
LogContext log = LogContext.current();
if (log instanceof SessionLog.Loggable) {
((SessionLog.Loggable)log).logStart(session);
} else if (log.isInfoLogged()) {
log.logInfo("Session " + session.id() + " started");
}
}
public static void end(Session session) { ... }
public interface Loggable {
void logStart(Session session);
void logEnd(Session session);
}
}
The use of interfaces (such as Loggable above) makes it easy
for any context to support customs logging events.
For example:
class MyLog extends StandardLog implements SessionLog.Loggable, DatabaseLog.Loggable {
... // Specialized logging for session and database events.
}
MyLog myLog = new MyLog();
LogContext.enter(myLog);
try {
...
LogContext.info("Informative message"); // Standard logging.
...
DatabaseLog.fail(transaction); // Database custom logging.
...
SessionLog.start(session); // Session custom logging.
...
} finally {
LogContext.exit(myLog);
}
| Field Summary | |
|---|---|
static LogContext |
NULL
Holds a context ignoring logging events. |
static StandardLog |
STANDARD
Holds a context forwarding log events to the root
java.util.logging.Logger framework (default logging context). |
static LogContext |
SYSTEM
Holds a context logging informative messages to System.out and warnings/errors events to
System.err. |
static LogContext |
SYSTEM_ERR
Holds a context logging warnings/errors events to System.err and ignoring informative messages. |
| Constructor Summary | |
|---|---|
LogContext()
Default constructor. |
|
| Method Summary | |
|---|---|
static LogContext |
current()
Returns the current logging context (or getDefault()
if the current thread has not entered any logging context). |
protected void |
enterAction()
The action to be performed after this context becomes the current context. |
static void |
error(java.lang.Throwable error)
Logs the specified error to the current logging context. |
static void |
error(java.lang.Throwable error,
java.lang.CharSequence message)
Logs the specified error and error message to the current logging context. |
protected void |
exitAction()
The action to be performed before this context is no more the current context. |
static LogContext |
getDefault()
Returns the default logging context for new threads ( STANDARD when not explicitly set). |
static void |
info(java.lang.CharSequence message)
Logs the specified informative message. |
abstract boolean |
isErrorLogged()
Indicates if errors are logged. |
abstract boolean |
isInfoLogged()
Indicates if informative messages are logged. |
abstract boolean |
isWarningLogged()
Indicates if warning messages are logged. |
abstract void |
logError(java.lang.Throwable error,
java.lang.CharSequence message)
Logs the specified error. |
abstract void |
logInfo(java.lang.CharSequence message)
Logs the specified informative message. |
abstract void |
logWarning(java.lang.CharSequence message)
Logs the specified warning message. |
static void |
setDefault(LogContext defaultLog)
Sets the specified logging context as default. |
static void |
warning(java.lang.CharSequence message)
Logs the specified warning message to the current logging context. |
| Methods inherited from class javolution.realtime.Context |
|---|
clear, enter, enter, exit, exit, getOuter, getOwner |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final StandardLog STANDARD
java.util.logging.Logger framework (default logging context).
The info/warning/error events are mapped to the info/warning/severe
log levels respectively.
public static final LogContext NULL
public static final LogContext SYSTEM
System.out and warnings/errors events to
System.err.
public static final LogContext SYSTEM_ERR
System.err and ignoring informative messages.
| Constructor Detail |
|---|
public LogContext()
| Method Detail |
|---|
public static LogContext current()
getDefault()
if the current thread has not entered any logging context).
public static LogContext getDefault()
STANDARD when not explicitly set).
public static void setDefault(LogContext defaultLog)
defaultLog - the default logging context.public static void info(java.lang.CharSequence message)
message - the informative message being logged.logInfo(CharSequence)public static void warning(java.lang.CharSequence message)
message - the warning message being logged.logWarning(CharSequence)public static void error(java.lang.Throwable error)
error - the error being logged.
public static void error(java.lang.Throwable error,
java.lang.CharSequence message)
error - the error being logged.message - the supplementary message or null if none.public abstract boolean isInfoLogged()
true if informative messages are logged;
false otherwise.public abstract void logInfo(java.lang.CharSequence message)
message - the informative message being logged.public abstract boolean isWarningLogged()
true if warnings message are logged;
false otherwise.public abstract void logWarning(java.lang.CharSequence message)
message - the warning message being logged.public abstract boolean isErrorLogged()
true if errors are logged;
false otherwise.
public abstract void logError(java.lang.Throwable error,
java.lang.CharSequence message)
error - the error being logged.message - the associated message or null if none.protected void enterAction()
Context
enterAction in class Contextprotected void exitAction()
Context
exitAction in class Context
|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||