1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.org.iscream.core.loggers; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
> |
import uk.org.iscream.util.*; |
6 |
> |
import uk.org.iscream.core.*; |
7 |
|
import java.io.IOException; |
8 |
|
|
9 |
|
/** |
13 |
|
* @author $Author$ |
14 |
|
* @version $Id$ |
15 |
|
*/ |
16 |
< |
class MultiLogger implements LoggerImpl { |
16 |
> |
public class MultiLogger implements LoggerImpl { |
17 |
|
|
18 |
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
30 |
|
* Creates a new MultiLogger. |
31 |
|
*/ |
32 |
|
public MultiLogger() throws IOException { |
33 |
< |
_screenlog = new ScreenLogger(); |
34 |
< |
_filelog = new FileLogger(); |
35 |
< |
write(this.toString(), Logger.SYSINIT, "started"); |
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 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 |
44 |
< |
* objects and the output ending up merged on the screen. |
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 |
< |
* @param source A string representation of the calling object. |
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 |
< |
* @param message The text to be logged. |
53 |
< |
*/ |
54 |
< |
public synchronized void write(String source, int verbosity, String message) { |
55 |
< |
_screenlog.write(source, verbosity, message); |
52 |
< |
_filelog.write(source, verbosity, 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 this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
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; |
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 |
|
|