public final class Logger extends Object implements ILogLevels
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:
ILogLevelsALL, 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| 限定符和类型 | 方法和说明 |
|---|---|
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).
|
static Logger |
create(int level,
PrintWriter out,
String prefix,
Set classMask) |
static Logger |
create(int level,
PrintWriter out,
String prefix,
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.
|
PrintWriter |
getWriter()
Provides direct access to the PrintWriter used by this Logger.
|
void |
info(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,
String msg,
boolean logCaller)
Logs 'msg' from an unnamed calling method.
|
void |
log(int level,
String method,
String msg,
boolean logCaller)
Logs 'msg' from a given calling method.
|
void |
log(int level,
String method,
String msg,
Throwable throwable)
Logs 'msg' from a given calling method followed by the 'throwable' stack
trace dump.
|
void |
log(int level,
String msg,
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(String level) |
void |
trace1(String method,
String msg)
A convenience method equivalent to log(TRACE1, method, msg).
|
void |
trace2(String method,
String msg)
A convenience method equivalent to log(TRACE2, method, msg).
|
void |
trace3(String method,
String msg)
A convenience method equivalent to log(TRACE3, method, msg).
|
void |
verbose(String msg)
A convenience method to log 'msg' from an anonymous calling method
at VERBOSE level.
|
void |
warning(String msg)
A convenience method to log 'msg' from an anonymous calling method
at WARNING level.
|
public static Logger create(int level, PrintWriter out, String prefix, Set classMask)
public static Logger create(int level, PrintWriter out, String prefix, Set classMask, Logger base)
level - out - prefix - classMask - base - public final boolean isLoggable(int level)
ILogLevelspublic final boolean atINFO()
public final boolean atVERBOSE()
public final boolean atTRACE1()
public final boolean atTRACE2()
public final boolean atTRACE3()
public final void warning(String msg)
msg - log message [ignored if null]public final void info(String msg)
msg - log message [ignored if null]public final void verbose(String msg)
msg - log message [ignored if null]public final void trace1(String method, String msg)
method - calling method name [ignored if null]msg - log message [ignored if null]public final void trace2(String method, String msg)
method - calling method name [ignored if null]msg - log message [ignored if null]public final void trace3(String method, String msg)
method - calling method name [ignored if null]msg - log message [ignored if null]public final void log(int level,
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,
String method,
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,
String msg,
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,
String method,
String msg,
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 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(String level)
Copyright © 2018. All rights reserved.