public class Reporters extends Object
Reporters utility class provides static factory methods
for the creation of various instances of Reporter. The
reporters created wrap various output methods from writers to
streams to files to standard output to nothing.
Each of the primitive implementations is itself thread safe because calls to report are synchronized.
The compound reporter produced by tee(Reporter[]) will
be thread safe if each of its contained reporters is thread safe.
None of the reporters are serializable.
| Modifier and Type | Method and Description |
|---|---|
static Reporter |
file(File f,
String encoding)
Return a reporter that writes to the specified file
using the specified encoding.
|
static Reporter |
silent()
Returns a silent reporter that writes its output
nowhere.
|
static Reporter |
stdOut()
Return a reporter that writes to standard output using
the UTF-8 character encoding.
|
static Reporter |
stream(OutputStream out,
String encoding)
Return a reporter that writes to the specified output
stream using the specified encoding.
|
static Reporter |
tee(Reporter... reporters)
Returns a compound reporter that sends reports to all of the
specified reporters.
|
static Reporter |
writer(Writer writer)
Return a reporter that writes to the specified print
writer.
|
public static Reporter writer(Writer writer)
The initial log level is LogLevel.NONE. This
may be reset using the method Reporter.setLevel(LogLevel).
writer - Writer to use for reporting.public static Reporter stream(OutputStream out, String encoding) throws UnsupportedCharsetException
out - Output stream to which to write.encoding - Encoding to use for writing.UnsupportedCharsetException - If the encoding is not
supported.public static Reporter file(File f, String encoding) throws IOException
f - File to which to write.encoding - Character encoding to use for writing.UnsupportedCharsetException - If the encoding is not supported.IOException - If the file is not found.public static Reporter stdOut()
System.out.
To write to standard output using a different character set,
use the factory method stream(OutputStream,String)
with the stream set to System.out.
UnsupportedCharsetException - If this platform does not
support UTF-8; the Java specification requires UTF-8 support,
so this should not occur on standard platforms.public static Reporter tee(Reporter... reporters)
The compound reporter may have its log level set like any reporter. Only reports at a log level whose severity is enabled are reported to the contained reporters through their report methods.
To allow the compound reporter to control logging levels for
the contained reporters, set the contained reporters log levels
to LogLevel.ALL so that they report all messages sent
to them by the compound reporter. For instance:
for (Reporter reporter : reporters)
reporter.setLevel(LogLevel.ALL);
Reporter rep = Reporters.tee(reporters);
rep.setLevel(LogLevel.DEBUG);
creates a compound logger printing messages to all contained
reporters at or above the debug level of severity.reporters - A variable-length list of reporters.public static Reporter silent()
dev/null
on a Unix machine.
The log levle on this reporter is fixed at LogLevel.NONE. Although levels may be set on silent
reporters, no matter what level is set, nothing is output.
There is only a single silent reporter that is returned for all calls to this method.
Copyright © 2016 Alias-i, Inc.. All rights reserved.