1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
|
3 |
|
|
//---IMPORTS--- |
4 |
|
|
import uk.ac.ukc.iscream.core.*; |
5 |
|
|
import java.io.IOException; |
6 |
|
|
|
7 |
|
|
/** |
8 |
|
|
* The MultiLogger is just a gateway to both the ScreenLogger |
9 |
|
|
* and the FileLogger. |
10 |
|
|
* |
11 |
|
|
* @author $Author$ |
12 |
|
|
* @version $Id$ |
13 |
|
|
*/ |
14 |
|
|
class MultiLogger implements LoggerImpl { |
15 |
|
|
|
16 |
|
|
//---FINAL ATTRIBUTES--- |
17 |
|
|
|
18 |
|
|
/** |
19 |
|
|
* The current CVS revision of this class |
20 |
|
|
*/ |
21 |
|
|
public final String REVISION = "$Revision: 1.1 $"; |
22 |
|
|
|
23 |
|
|
//---STATIC METHODS--- |
24 |
|
|
|
25 |
|
|
//---CONSTRUCTORS--- |
26 |
|
|
|
27 |
|
|
/** |
28 |
|
|
* Creates a new MultiLogger. |
29 |
|
|
*/ |
30 |
|
|
public MultiLogger() throws IOException { |
31 |
|
|
_screenlog = new ScreenLogger(); |
32 |
|
|
_filelog = new FileLogger(); |
33 |
|
|
write(this.toString(), Logger.SYSINIT, "started"); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
//---PUBLIC METHODS--- |
37 |
|
|
|
38 |
|
|
/** |
39 |
|
|
* The write() method takes a message, formats it using the |
40 |
|
|
* formatLogLine() method, and then outputs it to the screen |
41 |
|
|
* using System.out.println(). The source is usually the |
42 |
|
|
* calling object, referenced by `this'. The method has been |
43 |
|
|
* made synchronized to avoid it being called by two different |
44 |
|
|
* objects and the output ending up merged on the screen. |
45 |
|
|
* |
46 |
|
|
* @param source A string representation of the calling object. |
47 |
|
|
* @param verbosity the verbosity of this message |
48 |
|
|
* @param message The text to be logged. |
49 |
|
|
*/ |
50 |
|
|
public synchronized void write(String source, int verbosity, String message) { |
51 |
|
|
_screenlog.write(source, verbosity, message); |
52 |
|
|
_filelog.write(source, verbosity, message); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
57 |
|
|
* method to provide clean logging (every class should have this). |
58 |
|
|
* |
59 |
|
|
* @return the name of this class and its CVS revision |
60 |
|
|
*/ |
61 |
|
|
public String toString() { |
62 |
|
|
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
63 |
|
|
} |
64 |
|
|
//---PRIVATE METHODS--- |
65 |
|
|
|
66 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
67 |
|
|
|
68 |
|
|
//---ATTRIBUTES--- |
69 |
|
|
|
70 |
|
|
/** |
71 |
|
|
* A reference to the ScreenLogger we'll use |
72 |
|
|
*/ |
73 |
|
|
private LoggerImpl _screenlog; |
74 |
|
|
|
75 |
|
|
/** |
76 |
|
|
* A reference to the FileLogger we'll use |
77 |
|
|
*/ |
78 |
|
|
private LoggerImpl _filelog; |
79 |
|
|
|
80 |
|
|
//---STATIC ATTRIBUTES--- |
81 |
|
|
|
82 |
|
|
} |