public class Logger
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ALL
ALL indicates that all messages should be logged.
|
static int |
CONFIG
CONFIG is a message level for static configuration messages.
|
static Stream |
DEBUG_CONSOLE
Stream where the bytes are written to the debug console
|
static int |
FINE
FINE is a message level providing tracing information.
|
static int |
FINER
FINER indicates a fairly detailed tracing message.
|
static int |
FINEST
FINEST indicates a highly detailed tracing message.
|
static int |
INFO
INFO is a message level for informational messages.
|
static int |
OFF
OFF is a special level that can be used to turn off logging.
|
static int |
SEVERE
SEVERE is a message level indicating a serious failure.
|
static int |
WARNING
WARNING is a message level indicating a potential problem.
|
Modifier and Type | Method and Description |
---|---|
void |
addOutputHandler(Stream output)
Adds an output stream to the logger's output handler set.
|
void |
config(java.lang.String message)
Log a CONFIG message.
|
void |
dispose(boolean closeOutputHandlers)
Permanently discard this logger, removing it from the loggers registry.
|
void |
entering(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String params)
Log a method entry.
|
void |
exiting(java.lang.String sourceClass,
java.lang.String sourceMethod)
Log a method return.
|
void |
fine(java.lang.String message)
Log a FINE message.
|
void |
finer(java.lang.String message)
Log a FINER message.
|
void |
finest(java.lang.String message)
Log a FINEST message.
|
static int |
getDefaultLevel()
Returns the initial logger level, which is used when a new logger is created.
|
static java.lang.String |
getDefaultSeparator()
Returns the initial message separator, which is used when a new logger is
created.
|
static Logger |
getGlobalLogger()
Returns the global anonymous logger.
|
int |
getLevel()
Returns the current logger level.
|
static Logger |
getLogger(java.lang.String name)
Returns the logger with a specific name, keeping its level and output
handlers unchanged.
|
static Logger |
getLogger(java.lang.String name,
int level)
Returns the logger with a specific name, setting the level specified
and keeping the output handlers unchanged.
|
static Logger |
getLogger(java.lang.String name,
int level,
Stream outputStream)
Returns the logger with a specific name, setting the level specified
and optionally adding the given stream to the list of output handlers.
|
java.lang.String |
getName()
Returns the logger name.
|
Stream[] |
getOutputHandlers()
Get the output handlers associated with this logger.
|
java.lang.String |
getSeparator()
Gets the string used to separate two log messages.
|
void |
info(java.lang.String message)
Log a INFO message.
|
void |
log(int level,
java.lang.String message,
boolean prependInfo)
Logs a given message.
|
void |
logInfo(java.lang.StringBuffer message)
Used internally.
|
boolean |
removeOutputHandler(Stream output)
Removes an output handler from the logger's output handler set.
|
static void |
setDefaultLevel(int level)
Sets the initial logger level, which will be used when a new logger is created.
|
static void |
setDefaultSeparator(java.lang.String separator)
Sets the initial message separator, which will be used when a new logger is
created.
|
void |
setLevel(int level)
Sets the current logger level.
|
void |
setSeparator(java.lang.String separator)
Sets the string used to separate two log messages.
|
void |
severe(java.lang.String message)
Log a SEVERE message.
|
void |
throwing(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.Throwable thrown)
Log throwing an exception.
|
void |
warning(java.lang.String message)
Log a WARNING message.
|
public static final int OFF
public static final int FINEST
public static final int FINER
public static final int FINE
public static final int CONFIG
public static final int INFO
public static final int WARNING
public static final int SEVERE
public static final int ALL
public static final Stream DEBUG_CONSOLE
public static Logger getLogger(java.lang.String name)
name
- The logger name.java.lang.NullPointerException
- if name is null.public static Logger getLogger(java.lang.String name, int level)
name
- The logger name.level
- The logger level to set or -1 to keep it unchanged.java.lang.NullPointerException
- if name is null.public static Logger getLogger(java.lang.String name, int level, Stream outputStream)
name
- The logger name.level
- The logger level to set or -1 to keep it unchanged.outputStream
- The stream to add to the logger's list of output
handlers or null
to keep it unchanged.java.lang.NullPointerException
- if name is null.public static Logger getGlobalLogger()
public java.lang.String getName()
public int getLevel()
public void setLevel(int level)
level
- The logger level to set. This should be a composition of one or more
of the message types constants (FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE) or
OFF, if you want to disable all logging, or ALL, if you want to enable all logging.public static void setDefaultLevel(int level)
level
- The logger level to set. This should be a composition of one or more
of the message types constants (FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE) or
OFF, if you want to disable all logging, or ALL, if you want to enable all logging.public static int getDefaultLevel()
public java.lang.String getSeparator()
public void setSeparator(java.lang.String separator)
separator
- The string written after each log message.public static void setDefaultSeparator(java.lang.String separator)
separator
- The separator string.public static java.lang.String getDefaultSeparator()
public void addOutputHandler(Stream output)
output
- The output stream.public boolean removeOutputHandler(Stream output)
output
- The output stream.public Stream[] getOutputHandlers()
public void log(int level, java.lang.String message, boolean prependInfo)
level
- The message level.message
- The message to log.prependInfo
- A flag indicating whether this log message must be prepended
with the current date and time, level string, logger name, etc.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void logInfo(java.lang.StringBuffer message)
public void finest(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void finer(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void fine(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void config(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void info(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void warning(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void severe(java.lang.String message)
message
- The message to log.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String params)
sourceClass
- The name of class that issued the logging request.sourceMethod
- name of method that is being entered.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)
sourceClass
- The name of class that issued the logging request.sourceMethod
- The name of method that is being returned.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)
sourceClass
- he name of class that issued the logging request.sourceMethod
- The name of method that is throwing the exception.thrown
- The Throwable that is being thrown.java.lang.NullPointerException
- if one or more registered output handler
streams are null or this logger has been disposed.public void dispose(boolean closeOutputHandlers)
closeOutputHandlers
- If true
, all output handler streams
will be closed before disposing this logger.