1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
ajm |
1.2 |
package uk.ac.ukc.iscream.core.loggers; |
3 |
tdb |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
ajm |
1.3 |
import uk.ac.ukc.iscream.util.*; |
6 |
|
|
import uk.ac.ukc.iscream.core.*; |
7 |
tdb |
1.1 |
import java.io.IOException; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* The MultiLogger is just a gateway to both the ScreenLogger |
11 |
|
|
* and the FileLogger. |
12 |
|
|
* |
13 |
ajm |
1.3 |
* @author $Author: ajm4 $ |
14 |
|
|
* @version $Id: MultiLogger.java,v 1.2 2000/11/29 21:27:25 ajm4 Exp $ |
15 |
tdb |
1.1 |
*/ |
16 |
|
|
class MultiLogger implements LoggerImpl { |
17 |
|
|
|
18 |
|
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The current CVS revision of this class |
22 |
|
|
*/ |
23 |
ajm |
1.3 |
public final String REVISION = "$Revision: 1.2 $"; |
24 |
tdb |
1.1 |
|
25 |
|
|
//---STATIC METHODS--- |
26 |
|
|
|
27 |
|
|
//---CONSTRUCTORS--- |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* Creates a new MultiLogger. |
31 |
|
|
*/ |
32 |
|
|
public MultiLogger() throws IOException { |
33 |
ajm |
1.3 |
_screenlog = new ScreenLogger(); |
34 |
|
|
_filelog = new FileLogger(); |
35 |
|
|
write(toString(), Logger.SYSINIT, "started"); |
36 |
tdb |
1.1 |
} |
37 |
|
|
|
38 |
|
|
//---PUBLIC METHODS--- |
39 |
|
|
|
40 |
|
|
/** |
41 |
ajm |
1.3 |
* The write() method takes a message, formats it using the |
42 |
|
|
* formatLogLine() method, and then outputs it to the screen |
43 |
|
|
* using System.out.println(). The source is usually the |
44 |
|
|
* calling object, referenced by `this'. The method has been |
45 |
|
|
* made synchronized to avoid it being called by two different |
46 |
|
|
* objects and the output ending up merged on the screen. |
47 |
|
|
* |
48 |
|
|
* @param source A string representation of the calling object. |
49 |
|
|
* @param verbosity the verbosity of this message |
50 |
|
|
* @param message The text to be logged. |
51 |
|
|
*/ |
52 |
tdb |
1.1 |
public synchronized void write(String source, int verbosity, String message) { |
53 |
|
|
_screenlog.write(source, verbosity, message); |
54 |
|
|
_filelog.write(source, verbosity, message); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
59 |
|
|
* method to provide clean logging (every class should have this). |
60 |
|
|
* |
61 |
ajm |
1.3 |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
62 |
|
|
* to format the toString() |
63 |
|
|
* |
64 |
tdb |
1.1 |
* @return the name of this class and its CVS revision |
65 |
|
|
*/ |
66 |
|
|
public String toString() { |
67 |
ajm |
1.3 |
return FormatName.getName( |
68 |
|
|
_name, |
69 |
|
|
getClass().getName(), |
70 |
|
|
REVISION); |
71 |
tdb |
1.1 |
} |
72 |
ajm |
1.3 |
|
73 |
tdb |
1.1 |
//---PRIVATE METHODS--- |
74 |
|
|
|
75 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
76 |
|
|
|
77 |
|
|
//---ATTRIBUTES--- |
78 |
|
|
|
79 |
ajm |
1.3 |
/** |
80 |
|
|
* A reference to the ScreenLogger we'll use |
81 |
|
|
*/ |
82 |
|
|
private LoggerImpl _screenlog; |
83 |
|
|
|
84 |
|
|
/** |
85 |
|
|
* A reference to the FileLogger we'll use |
86 |
|
|
*/ |
87 |
|
|
private LoggerImpl _filelog; |
88 |
|
|
|
89 |
|
|
/** |
90 |
|
|
* This is the friendly identifier of the |
91 |
|
|
* component this class is running in. |
92 |
|
|
* eg, a Filter may be called "filter1", |
93 |
|
|
* If this class does not have an owning |
94 |
|
|
* component, a name from the configuration |
95 |
|
|
* can be placed here. This name could also |
96 |
|
|
* be changed to null for utility classes. |
97 |
|
|
*/ |
98 |
|
|
private String _name = Core.NAME; |
99 |
tdb |
1.1 |
|
100 |
|
|
//---STATIC ATTRIBUTES--- |
101 |
|
|
|
102 |
|
|
} |