|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.io.Logger
public class Logger
Message logger (logging output stream).
A logging output stream is used to write diagnostic log messages to during the execution of one or more programs. Typically, the output stream is a log file on disk that is opened for a given application and execution date.
Field Summary | |
---|---|
protected java.lang.StringBuffer |
m_buf
Output text line buffer. |
protected int |
m_filter
Maximum message verbosity filtering level. |
protected java.lang.String |
m_id
Name of this message logger. |
protected java.io.PrintWriter |
m_out
Underlying output stream. |
protected int |
m_pfx
Message prefixing bitflags. |
protected java.io.PrintWriter |
m_sus
Suspended output stream. |
(package private) static java.lang.String |
REV
Revision information. |
protected static java.lang.String |
SEV_N_DEBUG
Severity name: Debug. |
protected static java.lang.String |
SEV_N_ERROR
Severity name: Error. |
protected static java.lang.String |
SEV_N_FATAL
Severity name: Fatal (unrecoverable) error. |
protected static java.lang.String |
SEV_N_INFO
Severity name: Informational. |
protected static java.lang.String |
SEV_N_INTERNAL
Severity name: Internal (unrecoverable) fatal error. |
protected static java.lang.String |
SEV_N_UNKNOWN
Severity name: Unknown. |
protected static java.lang.String |
SEV_N_WARNING
Severity name: Warning. |
Fields inherited from interface tribble.io.LoggerI |
---|
PFX__DFL, PFX_DATE, PFX_LOC, PFX_NONE, PFX_TIME, SEV_DEBUG, SEV_ERROR, SEV_FATAL, SEV_INFO, SEV_INTERNAL, SEV_WARNING |
Constructor Summary | |
---|---|
Logger()
Default constructor. |
|
Logger(java.io.Writer out)
Constructor. |
Method Summary | |
---|---|
void |
close()
Close this message logger. |
void |
debug(int verbos,
java.lang.String loc,
java.lang.String msg)
Write a formatted debugging message to this message logger. |
void |
error(java.lang.String loc,
java.lang.String msg)
Write a formatted error message to this message logger. |
void |
fatal(java.lang.String loc,
java.lang.String msg)
Write a formatted fatal error message to this message logger. |
static Logger |
getLogger(java.lang.String id)
Retrieve a named message logger from the global logger list. |
java.lang.String |
getName()
Retrieve the name of this message logger. |
java.io.PrintWriter |
getOutput()
Retrieve the underlying output stream for this message logger. |
void |
info(int verbos,
java.lang.String loc,
java.lang.String msg)
Write a formatted informational message to this message logger. |
boolean |
isSuspended()
Determine if this logging stream is suspended or not. |
void |
log(int sev,
int verbos,
java.lang.String loc,
java.lang.String msg)
Write a formatted message to this message logger. |
protected void |
printMessage(int sev,
int verbos,
java.lang.String loc,
java.lang.String msg)
Write a formatted message to this message logger. |
void |
register(java.lang.String id)
Register this message logger in the global logger list. |
protected static void |
registerLogger(Logger log,
java.lang.String id)
Register a named message logger in the global logger list. |
void |
resume()
Resume subsequent output written to this logging stream. |
void |
setOutput(java.io.Writer out)
Establish the underlying output stream for this message logger. |
int |
setPrefix(int pfx)
Establish the prefixes to be prepended to messages written to this message logger. |
int |
setVerbosity(int sev,
int max)
Establish the verbosity filtering level for this message logger. |
protected static java.lang.String |
severityToString(int sev)
Return the string corresponding to a given logging message severity level. |
void |
suspend()
Suspend subsequent output written to this logging stream. |
void |
unregister()
Unregister this named message logger from the global logger list. |
protected static void |
unregisterLogger(Logger log)
Unregister a named message logger from the global logger list. |
void |
warning(int verbos,
java.lang.String loc,
java.lang.String msg)
Write a formatted warning message to this message logger. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String REV
protected static final java.lang.String SEV_N_UNKNOWN
protected static final java.lang.String SEV_N_DEBUG
protected static final java.lang.String SEV_N_INFO
protected static final java.lang.String SEV_N_WARNING
protected static final java.lang.String SEV_N_ERROR
protected static final java.lang.String SEV_N_FATAL
protected static final java.lang.String SEV_N_INTERNAL
protected java.io.PrintWriter m_out
protected java.io.PrintWriter m_sus
protected java.lang.String m_id
protected int m_pfx
protected int m_filter
protected java.lang.StringBuffer m_buf
Constructor Detail |
---|
public Logger()
setOutput(java.io.Writer)
public Logger(java.io.Writer out)
out
- An output stream to be the underlying output stream for this message
logger.Method Detail |
---|
public static Logger getLogger(java.lang.String id)
id
- The name that a message logger was registered with.
register(java.lang.String)
protected static java.lang.String severityToString(int sev)
sev
- The severity level of the message, which should be one of the
SEV_XXX constants.
protected static void registerLogger(Logger log, java.lang.String id)
Note that if the logger is currently registered with a different name, it will first be unregistered under that name and then re-registered with the new name.
log
- A message logger.id
- The name that the message logger is to be registered with.
java.lang.NullPointerException
- (unchecked)
Thrown if log or id is null.
java.lang.IllegalArgumentException
- (unchecked)
Thrown if a message logger is already registered with the given name.getLogger(java.lang.String)
,
unregisterLogger(tribble.io.Logger)
,
register(java.lang.String)
protected static void unregisterLogger(Logger log)
log
- A message logger.
If the logger has no name or is not currently registered, no operation is
performed.
Note that the default (unnamed) message logger cannot be unregistered.close()
,
registerLogger(tribble.io.Logger, java.lang.String)
,
unregister()
public void setOutput(java.io.Writer out)
setOutput
in interface LoggerI
out
- A logging output stream.
This can be null.
If the stream is not an instance of a java.io.PrintWriter object,
one will be created internally.public java.io.PrintWriter getOutput()
getOutput
in interface LoggerI
public void close()
Note that the default (unnamed) message logger cannot be closed.
Although this operation close the underlying output stream for this
logger, it does not unregister it. To change the underlying output stream
for this logger without closing the current output stream, use
setOutput(java.io.Writer)
instead of this method.
Note that this method does not throw any checked exceptions, especially java.io.IOException.
close
in interface LoggerI
close
in interface SuspendableWriterI
setOutput(java.io.Writer)
,
unregister()
public void suspend()
Output to this stream can be resumed by calling resume()
.
This method may be called multiple times without any intervening call to
resume()
without any ill effects.
suspend
in interface SuspendableWriterI
resume()
public void resume()
Output to this stream can be suspended by calling suspend()
.
This method may be called multiple times without any previous or
intervening call to suspend()
without any ill effects.
resume
in interface SuspendableWriterI
suspend()
public boolean isSuspended()
isSuspended
in interface SuspendableWriterI
suspend()
public java.lang.String getName()
public void register(java.lang.String id)
Note that if this logger is currently registered with a different name, it will first be unregistered under that name and then re-registered with the new name.
id
- The name that the message logger is to be registered with.
The logger is assigned this name (until it is registered with a different
name).
java.lang.NullPointerException
- (unchecked)
Thrown if log or id is null.
java.lang.IllegalArgumentException
- (unchecked)
Thrown if a message logger is already registered with the given name.unregister()
,
getLogger(java.lang.String)
,
getName()
public void unregister()
If this logger is not currently registered, no operation is performed.
Note that the default (unnamed) message logger cannot be unregistered.
register(java.lang.String)
,
close()
public int setPrefix(int pfx)
setPrefix
in interface LoggerI
pfx
- Zero or more of the
PFX_XXX
prefixing bitflag constants or-ed together.
public int setVerbosity(int sev, int max)
setVerbosity
in interface LoggerI
sev
- The severity of the messages to be filtered.
This should be one of the SEV_XXX
constants, or zero to specify all message severities.max
- The maximum verbosity filtering level for messages written to
this message logger.
Log messages with a verbosity level not greater than this value will be
written to the logging output stream; those with a verbosity level greater
than this value will be ignored.
public void log(int sev, int verbos, java.lang.String loc, java.lang.String msg)
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
log
in interface LoggerI
sev
- The severity of the message, which should be one of the
SEV_XXX constants.verbos
- The verbosity level of the message.
The higher the level, the more verbose the message (i.e., the more
frequently the message is logged) and thus the more likely it will be
filtered and not written to the output stream; messages with a level of
zero will always be written to the output stream.loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.public void debug(int verbos, java.lang.String loc, java.lang.String msg)
SEV_DEBUG
.
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
debug
in interface LoggerI
verbos
- The verbosity level of the message.
The higher the level, the more verbose the message (i.e., the more
frequently the message is logged) and thus the more likely it will be
filtered and not written to the output stream; messages with a level of
zero will always be written to the output stream.loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.public void info(int verbos, java.lang.String loc, java.lang.String msg)
SEV_INFO
.
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
info
in interface LoggerI
verbos
- The verbosity level of the message.
The higher the level, the more verbose the message (i.e., the more
frequently the message is logged) and thus the more likely it will be
filtered and not written to the output stream; messages with a level of
zero will always be written to the output stream.loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.public void warning(int verbos, java.lang.String loc, java.lang.String msg)
SEV_WARNING
.
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
warning
in interface LoggerI
verbos
- The verbosity level of the message.
The higher the level, the more verbose the message (i.e., the more
frequently the message is logged) and thus the more likely it will be
filtered and not written to the output stream; messages with a level of
zero will always be written to the output stream.loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.public void error(java.lang.String loc, java.lang.String msg)
SEV_ERROR
.
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
error
in interface LoggerI
loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.public void fatal(java.lang.String loc, java.lang.String msg)
SEV_FATAL
.
Note that this method does not throw any checked exceptions, specifically java.io.IOException.
fatal
in interface LoggerI
loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no location is written.msg
- A text message to log.protected void printMessage(int sev, int verbos, java.lang.String loc, java.lang.String msg)
Note that this method does not throw any checked exceptions, especially java.io.IOException.
sev
- The severity level of the message, which should be one of the
SEV_XXX constants.verbos
- The verbosity level of the message.
The higher the level, the more verbose the message (i.e., the more
frequently the message is logged) and thus the more likely it will be
filtered and not written to the output stream; messages with a level of
zero will always be written to the output stream.loc
- The name of the location (typically a thread or class name) from where the
log message originates. This serves as a label to prefix the message with
in the logging output stream. This can be empty ("") or null, in
which case no prefix is written.msg
- A text message to log.
Note that this message should not have a terminating newline
character.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |