01: package Shared.Logging.Internal;
02:
03: import java.io.*;
04: import java.io.PrintStream;
05:
06: /**
07: * The formatter used by default.
08: */
09: public class ConsoleLogger extends GenericLogger {
10:
11: private PrintStream printStream;
12:
13: public ConsoleLogger(String logIdentifier) {
14: super (logIdentifier);
15: this .printStream = System.out;
16: }
17:
18: /**
19: * Writes the log text to System.out.
20: */
21: public synchronized void publish(String levelName, String message) {
22: this .printStream.println(super .getLogText(levelName, message));
23: this .printStream.flush();
24: }
25:
26: /**
27: * Writes the stacktrace to System.out.
28: */
29: public synchronized void publish(String levelName,
30: Throwable throwable) {
31: this .printStream.println(super .getThrowableText(levelName,
32: throwable));
33: this .printStream.flush();
34: }
35:
36: /**
37: * This one just logs the message directly without any formatting.
38: */
39: public void publishDirectly(String message) {
40: this .printStream.println(message);
41: this .printStream.flush();
42: }
43:
44: /**
45: * This is called by the Logs shutdown hook.
46: * The logger must close any open streams and if required
47: * do further cleanup. The JVM will shutdown short time
48: * after this call.
49: */
50: public void terminate() {
51: // no action required for this logger.
52: }
53:
54: } // ConsoleLogger
|