public abstract class Reporter extends Object
Reporter is the abstract base class on which reporters
are defined that provide incremental feedback from long-running
tasks at various levels of granularity. See the utility class
Reporters for factory methods to create reporters with
various output sources ranging from files to writers to standard
output.
A reporter has a defined severity level, which is an instance of
LogLevel. A reporter will report (by whichever means at
its disposal) all reports at or above its specified severity level.
Whether a reporter will report a message reported at level may
be determined by calling isEnabled(LogLevel), which returns
true if a message at the specified level will be reported.
Messages are reported as simple strings at a specified log level
using report(LogLevel,String). It is up to specific
implementations to embellish these with time stamps, thread
identifiers, etc.
The severity level may be inspected using getLevel()
and changed using setLevel(LogLevel).
Reporting versus Logging
aAlthough this class behaves like other loggers, such as those found in Apache's Log4J or Java's util.logging package, it is not intended to replace them in server-side applications. Unlike these other loggers, reporters as defined in this abstract class are not configurable through reflection -- they are purely controlled through the API. Their intended use is in command-line programs that call long-running training or run methods.
Creating Reporters
The static utility class Reporters contains static
factory methods for creating a variety of different kinds of
reporters.
Thread Safety
The getLevel() and setLevel(LogLevel) methods
are synchronized with each other, and thus thread safe. If
reporters accept concurrent reports from multiple threads, the
report method should be synchronized. As long as the reporter uses
the getLevel() method to access the current log level, it
does not need to be synchronized with the get and set methods.
| Constructor and Description |
|---|
Reporter()
Construct an instance of a reporter with log level
LogLevel.NONE. |
Reporter(LogLevel level)
Construct an instance of a reporter with the specified log
level.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
close()
Close this reporter and free all resources associated with
it.
|
void |
debug(String msg)
Utility method for debug-level reports.
|
void |
error(String msg)
Utility method for error-level reports.
|
void |
fatal(String msg)
Utility method for fatal-level reports.
|
LogLevel |
getLevel()
Return the log level for this reporter.
|
void |
info(String msg)
Utility method for info-level reports.
|
boolean |
isDebugEnabled()
Returns
true if this reporter is enabled at
the debug level. |
boolean |
isEnabled(LogLevel level)
Returns
true if the specified level is at least as
severe as the level specified by this reporter. |
boolean |
isErrorEnabled()
Returns
true if this reporter is enabled at
the error level. |
boolean |
isFatalEnabled()
Returns
true if this reporter is enabled at
the fatal level. |
boolean |
isInfoEnabled()
Returns
true if this reporter is enabled at
the info level. |
boolean |
isTraceEnabled()
Returns
true if this reporter is enabled at
the trace level. |
boolean |
isWarnEnabled()
Returns
true if this reporter is enabled at
the warn level. |
abstract void |
report(LogLevel level,
String msg)
Reports the specified message if the specified level's severity
is at or above the level of this reporter.
|
Reporter |
setLevel(LogLevel level)
Sets the log level for this reporter to the specified level
and returns the reporter.
|
void |
trace(String msg)
Utility method for trace-level reports.
|
void |
warn(String msg)
Utility method for warn-level reports.
|
public Reporter()
LogLevel.NONE.public Reporter(LogLevel level)
level - Initial log level for this reporter.public abstract void report(LogLevel level, String msg)
The objects should be converted to strings and concatenated.
The default implementation in this class does nothing.
If this reporter supports concurrent reports from multiple threads, this method should in some way be synchronized.
level - Log level for this report instance.msg - Message to report.public void trace(String msg)
This is a convenience method calling report(LogLevel.TRACE,msg).
msg - Message to report.public void debug(String msg)
This is a convenience method calling report(LogLevel.DEBUG,msg).
msg - Message to report.public void info(String msg)
This is a convenience method calling report(LogLevel.INFO,msg).
msg - Message to report.public void warn(String msg)
This is a convenience method calling report(LogLevel.WARN,msg).
msg - Message to report.public void error(String msg)
This is a convenience method calling report(LogLevel.ERROR,msg).
msg - Message to report.public void fatal(String msg)
This is a convenience method calling report(LogLevel.FATAL,msg).
msg - Message to report.public final LogLevel getLevel()
The default implementation in this base class returns
LogLevel.NONE.
public boolean isEnabled(LogLevel level)
true if the specified level is at least as
severe as the level specified by this reporter.
This is a utility method that is equivalent to
LogLevel.COMPARATOR.compare(leve,getLevel()).
level - Level to test.true if the specified level will be reported.public boolean isTraceEnabled()
true if this reporter is enabled at
the trace level.
This is just a convenience method calling
isEnabled(LogLevel.TRACE).
true if trace reporting is enabled.public boolean isDebugEnabled()
true if this reporter is enabled at
the debug level.
This is just a convenience method calling
isEnabled(LogLevel.DEBUG).
true if debug reporting is enabled.public boolean isInfoEnabled()
true if this reporter is enabled at
the info level.
This is just a convenience method calling
isEnabled(LogLevel.INFO).
true if info reporting is enabled.public boolean isWarnEnabled()
true if this reporter is enabled at
the warn level.
This is just a convenience method calling
isEnabled(LogLevel.WARN).
true if warn reporting is enabled.public boolean isErrorEnabled()
true if this reporter is enabled at
the error level.
This is just a convenience method calling
isEnabled(LogLevel.ERROR).
true if error reporting is enabled.public boolean isFatalEnabled()
true if this reporter is enabled at
the fatal level.
This is just a convenience method calling
isEnabled(LogLevel.FATAL).
true if fatal reporting is enabled.public final Reporter setLevel(LogLevel level)
Reporter r = Reporters.stdOut().setLevel(LogLevel.DEBUG);
The default implementation in this class sets the logging level to the specified level and returns this reporter.
This method must return this reporter in order to be plug-and-play compatible with the built-in reporters.
level - New log level.public abstract void close()
The default implementation in this class does nothing.
Copyright © 2016 Alias-i, Inc.. All rights reserved.