1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.org.iscream.core.loggers; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.org.iscream.util.*; |
6 |
import uk.org.iscream.core.*; |
7 |
import java.io.IOException; |
8 |
|
9 |
/** |
10 |
* The MultiLogger is just a gateway to both the ScreenLogger |
11 |
* and the FileLogger. |
12 |
* |
13 |
* @author $Author: tdb1 $ |
14 |
* @version $Id: MultiLogger.java,v 1.6 2001/02/25 20:49:20 tdb1 Exp $ |
15 |
*/ |
16 |
public class MultiLogger implements LoggerImpl { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public final String REVISION = "$Revision: 1.6 $"; |
24 |
|
25 |
//---STATIC METHODS--- |
26 |
|
27 |
//---CONSTRUCTORS--- |
28 |
|
29 |
/** |
30 |
* Creates a new MultiLogger. |
31 |
*/ |
32 |
public MultiLogger() throws IOException { |
33 |
_screenlog = new ScreenLogger(); |
34 |
_filelog = new FileLogger(); |
35 |
write(toString(), Logger.SYSINIT, "started"); |
36 |
} |
37 |
|
38 |
//---PUBLIC METHODS--- |
39 |
|
40 |
/** |
41 |
* The write() method takes a line of text, pre-formatted |
42 |
* and outputs it using a method defined by the actual |
43 |
* implementation. The verbosity is given in case the |
44 |
* implementation wishes to utilise it in the layout - |
45 |
* eg. a different colour or font. |
46 |
* |
47 |
* This instance passes the message on to a ScreenLogger |
48 |
* and a FileLogger. |
49 |
* |
50 |
* @param line A line of formatted text to be logged |
51 |
* @param verbosity the verbosity of this message |
52 |
*/ |
53 |
public synchronized void write(String line, int verbosity) { |
54 |
_screenlog.write(line, verbosity); |
55 |
_filelog.write(line, verbosity); |
56 |
} |
57 |
|
58 |
/** |
59 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
60 |
* method to provide clean logging (every class should have this). |
61 |
* |
62 |
* This uses the uk.org.iscream.util.FormatName class |
63 |
* to format the toString() |
64 |
* |
65 |
* @return the name of this class and its CVS revision |
66 |
*/ |
67 |
public String toString() { |
68 |
return FormatName.getName( |
69 |
_name, |
70 |
getClass().getName(), |
71 |
REVISION); |
72 |
} |
73 |
|
74 |
//---PRIVATE METHODS--- |
75 |
|
76 |
/** |
77 |
* This method is provided if this class wishes to log |
78 |
* a message itself. |
79 |
* |
80 |
* @param source A String representation of the source |
81 |
* @param verbosity the verbosity of this message |
82 |
* @param message The message to log |
83 |
*/ |
84 |
private void write(String source, int verbosity, String message) { |
85 |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
86 |
} |
87 |
|
88 |
//---ACCESSOR/MUTATOR METHODS--- |
89 |
|
90 |
//---ATTRIBUTES--- |
91 |
|
92 |
/** |
93 |
* A reference to the ScreenLogger we'll use |
94 |
*/ |
95 |
private LoggerImpl _screenlog; |
96 |
|
97 |
/** |
98 |
* A reference to the FileLogger we'll use |
99 |
*/ |
100 |
private LoggerImpl _filelog; |
101 |
|
102 |
/** |
103 |
* This is the friendly identifier of the |
104 |
* component this class is running in. |
105 |
* eg, a Filter may be called "filter1", |
106 |
* If this class does not have an owning |
107 |
* component, a name from the configuration |
108 |
* can be placed here. This name could also |
109 |
* be changed to null for utility classes. |
110 |
*/ |
111 |
private String _name = Core.NAME; |
112 |
|
113 |
//---STATIC ATTRIBUTES--- |
114 |
|
115 |
} |