|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vladium.logging.Logger
A simple Java version-independent logging framework. Each Logger is also an immutable context that encapsulates configuration elements like the logging verbosity level etc. In general, a Logger is looked up as an inheritable thread-local piece of data. This decouples classes and logging configurations in a way that seems difficult with log4j.
Note that a given class is free to cache its context in an instance field if the class is instantiated and used only on a single thread (or a set of threads that are guaranteed to share the same logging context). [This is different from the usual log4j pattern of caching a logger in a class static field]. In other cases (e.g., the instrumentation runtime), it makes more sense to scope a context to a single method invocation.
Every log message is structured as follows:
ILogLevels
Nested Class Summary | |
private static class |
Logger.ThreadLocalStack
|
Field Summary | |
private static java.lang.String |
COMMA_DELIMITERS
|
private static boolean |
FLUSH_LOG
|
private java.util.Set |
m_classMask
|
private int |
m_level
|
private java.io.PrintWriter |
m_out
|
private java.lang.String |
m_prefix
|
private static java.lang.String |
PREFIX_TO_STRIP
|
private static int |
PREFIX_TO_STRIP_LENGTH
|
private static Logger |
STATIC_LOGGER
|
private static Logger.ThreadLocalStack |
THREAD_LOCAL_STACK
|
Fields inherited from interface com.vladium.logging.ILogLevels |
ALL, ALL_STRING, INFO, INFO_STRING, NONE, NONE_STRING, QUIET_STRING, SEVERE, SEVERE_STRING, SILENT_STRING, TRACE1, TRACE1_STRING, TRACE2, TRACE2_STRING, TRACE3, TRACE3_STRING, VERBOSE, VERBOSE_STRING, WARNING, WARNING_STRING |
Constructor Summary | |
private |
Logger(int level,
java.io.PrintWriter out,
java.lang.String prefix,
java.util.Set classMask)
|
Method Summary | |
private void |
_log(int level,
java.lang.String method,
java.lang.String msg,
boolean logCaller)
|
private void |
_log(int level,
java.lang.String method,
java.lang.String msg,
java.lang.Throwable throwable)
|
boolean |
atINFO()
A convenience method equivalent to isLoggable(INFO). |
boolean |
atTRACE1()
A convenience method equivalent to isLoggable(TRACE1). |
boolean |
atTRACE2()
A convenience method equivalent to isLoggable(TRACE2). |
boolean |
atTRACE3()
A convenience method equivalent to isLoggable(TRACE3). |
boolean |
atVERBOSE()
A convenience method equivalent to isLoggable(VERBOSE). |
private void |
cleanup()
|
static Logger |
create(int level,
java.io.PrintWriter out,
java.lang.String prefix,
java.util.Set classMask)
|
static Logger |
create(int level,
java.io.PrintWriter out,
java.lang.String prefix,
java.util.Set classMask,
Logger base)
This works as a cloning creator of sorts. |
static Logger |
getLogger()
Returns the current top of the thread-local logger stack or the static Logger instance scoped to Logger.class if the stack is empty. |
java.io.PrintWriter |
getWriter()
Provides direct access to the PrintWriter used by this Logger. |
void |
info(java.lang.String msg)
A convenience method to log 'msg' from an anonymous calling method at INFO level. |
boolean |
isLoggable(int level)
A quick method to determine if logging is enabled at a given level. |
void |
log(int level,
java.lang.String msg,
boolean logCaller)
Logs 'msg' from an unnamed calling method. |
void |
log(int level,
java.lang.String method,
java.lang.String msg,
boolean logCaller)
Logs 'msg' from a given calling method. |
void |
log(int level,
java.lang.String method,
java.lang.String msg,
java.lang.Throwable throwable)
Logs 'msg' from a given calling method followed by the 'throwable' stack trace dump. |
void |
log(int level,
java.lang.String msg,
java.lang.Throwable throwable)
Logs 'msg' from an unnamed calling method followed by the 'throwable' stack trace dump. |
static void |
pop(Logger ctx)
Requiring a context parameter here helps enforce correct push/pop nesting in the caller code. |
static void |
push(Logger ctx)
|
static int |
stringToLevel(java.lang.String level)
|
void |
trace1(java.lang.String method,
java.lang.String msg)
A convenience method equivalent to log(TRACE1, method, msg). |
void |
trace2(java.lang.String method,
java.lang.String msg)
A convenience method equivalent to log(TRACE2, method, msg). |
void |
trace3(java.lang.String method,
java.lang.String msg)
A convenience method equivalent to log(TRACE3, method, msg). |
void |
verbose(java.lang.String msg)
A convenience method to log 'msg' from an anonymous calling method at VERBOSE level. |
void |
warning(java.lang.String msg)
A convenience method to log 'msg' from an anonymous calling method at WARNING level. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private final int m_level
private final java.io.PrintWriter m_out
private final java.lang.String m_prefix
private final java.util.Set m_classMask
private static final java.lang.String PREFIX_TO_STRIP
private static final int PREFIX_TO_STRIP_LENGTH
private static final boolean FLUSH_LOG
private static final java.lang.String COMMA_DELIMITERS
private static final Logger STATIC_LOGGER
private static final Logger.ThreadLocalStack THREAD_LOCAL_STACK
Constructor Detail |
private Logger(int level, java.io.PrintWriter out, java.lang.String prefix, java.util.Set classMask)
Method Detail |
public static Logger create(int level, java.io.PrintWriter out, java.lang.String prefix, java.util.Set classMask)
public static Logger create(int level, java.io.PrintWriter out, java.lang.String prefix, java.util.Set classMask, Logger base)
level
- out
- prefix
- classMask
- base
-
public final boolean isLoggable(int level)
ILogLevels
public final boolean atINFO()
public final boolean atVERBOSE()
public final boolean atTRACE1()
public final boolean atTRACE2()
public final boolean atTRACE3()
public final void warning(java.lang.String msg)
msg
- log message [ignored if null]public final void info(java.lang.String msg)
msg
- log message [ignored if null]public final void verbose(java.lang.String msg)
msg
- log message [ignored if null]public final void trace1(java.lang.String method, java.lang.String msg)
method
- calling method name [ignored if null]msg
- log message [ignored if null]public final void trace2(java.lang.String method, java.lang.String msg)
method
- calling method name [ignored if null]msg
- log message [ignored if null]public final void trace3(java.lang.String method, java.lang.String msg)
method
- calling method name [ignored if null]msg
- log message [ignored if null]public final void log(int level, java.lang.String msg, boolean logCaller)
level
- level to log at [the method does nothing if this is less
than the set level].msg
- log message [ignored if null]public final void log(int level, java.lang.String method, java.lang.String msg, boolean logCaller)
level
- level to log at [the method does nothing if this is less
than the set level].method
- calling method name [ignored if null]msg
- log message [ignored if null]public final void log(int level, java.lang.String msg, java.lang.Throwable throwable)
level
- level to log at [the method does nothing if this is less
than the set level].msg
- log message [ignored if null]throwable
- to dump after message [ignored if null]public final void log(int level, java.lang.String method, java.lang.String msg, java.lang.Throwable throwable)
level
- level to log at [the method does nothing if this is less
than the set level].method
- calling method name [ignored if null]msg
- log message [ignored if null]throwable
- to dump after message [ignored if null]public java.io.PrintWriter getWriter()
public static Logger getLogger()
public static void push(Logger ctx)
ctx
- [may not be null]public static void pop(Logger ctx)
ctx
- [may not be null]public static int stringToLevel(java.lang.String level)
private void cleanup()
private void _log(int level, java.lang.String method, java.lang.String msg, boolean logCaller)
private void _log(int level, java.lang.String method, java.lang.String msg, java.lang.Throwable throwable)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |