1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.transaction.util; |
18 | |
|
19 | |
import java.io.PrintWriter; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class PrintWriterLogger implements LoggerFacade { |
28 | |
|
29 | |
protected PrintWriter printWriter; |
30 | |
protected String name; |
31 | |
protected boolean debug; |
32 | |
|
33 | 17 | public PrintWriterLogger(PrintWriter printWriter, String name, boolean debug) { |
34 | 17 | this.printWriter = printWriter; |
35 | 17 | this.name = name; |
36 | 17 | this.debug = debug; |
37 | 17 | } |
38 | |
|
39 | |
public LoggerFacade createLogger(String newName) { |
40 | 9 | return new PrintWriterLogger(this.printWriter, newName, this.debug); |
41 | |
} |
42 | |
|
43 | |
public void logInfo(String message) { |
44 | 10 | log("INFO", message); |
45 | 10 | } |
46 | |
|
47 | |
public void logFine(String message) { |
48 | 0 | if (debug) |
49 | 0 | log("FINE", message); |
50 | 0 | } |
51 | |
|
52 | |
public boolean isFineEnabled() { |
53 | 1353 | return debug; |
54 | |
} |
55 | |
|
56 | |
public void logFiner(String message) { |
57 | 0 | if (debug) |
58 | 0 | log("FINER", message); |
59 | 0 | } |
60 | |
|
61 | |
public boolean isFinerEnabled() { |
62 | 9002 | return debug; |
63 | |
} |
64 | |
|
65 | |
public void logFinest(String message) { |
66 | 0 | if (debug) |
67 | 0 | log("FINEST", message); |
68 | 0 | } |
69 | |
|
70 | |
public boolean isFinestEnabled() { |
71 | 3108 | return debug; |
72 | |
} |
73 | |
|
74 | |
public void logWarning(String message) { |
75 | 29 | log("WARNING", message); |
76 | 29 | } |
77 | |
|
78 | |
public void logWarning(String message, Throwable t) { |
79 | 0 | log("WARNING", message); |
80 | 0 | t.printStackTrace(printWriter); |
81 | 0 | } |
82 | |
|
83 | |
public void logSevere(String message) { |
84 | 0 | log("SEVERE", message); |
85 | 0 | } |
86 | |
|
87 | |
public void logSevere(String message, Throwable t) { |
88 | 0 | log("SEVERE", message); |
89 | 0 | t.printStackTrace(printWriter); |
90 | 0 | } |
91 | |
|
92 | |
protected void log(String level, String message) { |
93 | 39 | printWriter.write(name + "(" + level + ":" + message); |
94 | 39 | printWriter.flush(); |
95 | 39 | } |
96 | |
} |