public class Reporters extends Object
Reportersutility 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
be thread safe if each of its contained reporters is thread safe.
None of the reporters are serializable.
|Modifier and Type||Method and Description|
Return a reporter that writes to the specified file using the specified encoding.
Returns a silent reporter that writes its output nowhere.
Return a reporter that writes to standard output using the UTF-8 character encoding.
Return a reporter that writes to the specified output stream using the specified encoding.
Returns a compound reporter that sends reports to all of the specified reporters.
Return a reporter that writes to the specified print writer.
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
public static Reporter stdOut()
To write to standard output using a different character set,
use the factory method
with the stream set to
UnsupportedCharsetException- If this platform does not support UTF-8; the Java specification requires UTF-8 support, so this should not occur on standard platforms.
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
LogLevel.ALL so that they report all messages sent
to them by the compound reporter. For instance:
creates a compound logger printing messages to all contained reporters at or above the debug level of severity.for (Reporter reporter : reporters) reporter.setLevel(LogLevel.ALL); Reporter rep = Reporters.tee(reporters); rep.setLevel(LogLevel.DEBUG);
reporters- A variable-length list of reporters.
public static Reporter silent()
dev/nullon 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.