1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.ac.ukc.iscream.core.loggers; |
22 |
> |
package uk.org.iscream.cms.server.core.loggers; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.core.LoggerImpl; |
26 |
< |
import uk.ac.ukc.iscream.core.Logger; |
25 |
> |
import uk.org.iscream.cms.util.*; |
26 |
> |
import uk.org.iscream.cms.server.core.*; |
27 |
|
import java.io.IOException; |
28 |
|
|
29 |
|
/** |
33 |
|
* @author $Author$ |
34 |
|
* @version $Id$ |
35 |
|
*/ |
36 |
< |
class MultiLogger implements LoggerImpl { |
36 |
> |
public class MultiLogger implements LoggerImpl { |
37 |
|
|
38 |
|
//---FINAL ATTRIBUTES--- |
39 |
|
|
50 |
|
* Creates a new MultiLogger. |
51 |
|
*/ |
52 |
|
public MultiLogger() throws IOException { |
53 |
< |
_screenlog = new ScreenLogger(); |
54 |
< |
_filelog = new FileLogger(); |
55 |
< |
write(this.toString(), Logger.SYSINIT, "started"); |
53 |
> |
_screenlog = new ScreenLogger(); |
54 |
> |
_filelog = new FileLogger(); |
55 |
> |
write(toString(), Logger.SYSINIT, "started"); |
56 |
|
} |
57 |
|
|
58 |
|
//---PUBLIC METHODS--- |
59 |
|
|
60 |
|
/** |
61 |
< |
* The write() method takes a message, formats it using the |
62 |
< |
* formatLogLine() method, and then outputs it to the screen |
63 |
< |
* using System.out.println(). The source is usually the |
64 |
< |
* calling object, referenced by `this'. The method has been |
65 |
< |
* made synchronized to avoid it being called by two different |
46 |
< |
* objects and the output ending up merged on the screen. |
61 |
> |
* The write() method takes a line of text, pre-formatted |
62 |
> |
* and outputs it using a method defined by the actual |
63 |
> |
* implementation. The verbosity is given in case the |
64 |
> |
* implementation wishes to utilise it in the layout - |
65 |
> |
* eg. a different colour or font. |
66 |
|
* |
67 |
< |
* @param source A string representation of the calling object. |
67 |
> |
* This instance passes the message on to a ScreenLogger |
68 |
> |
* and a FileLogger. |
69 |
> |
* |
70 |
> |
* @param line A line of formatted text to be logged |
71 |
|
* @param verbosity the verbosity of this message |
72 |
< |
* @param message The text to be logged. |
73 |
< |
*/ |
74 |
< |
public synchronized void write(String source, int verbosity, String message) { |
75 |
< |
_screenlog.write(source, verbosity, message); |
54 |
< |
_filelog.write(source, verbosity, message); |
72 |
> |
*/ |
73 |
> |
public synchronized void write(String line, int verbosity) { |
74 |
> |
_screenlog.write(line, verbosity); |
75 |
> |
_filelog.write(line, verbosity); |
76 |
|
} |
77 |
|
|
78 |
|
/** |
79 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
80 |
|
* method to provide clean logging (every class should have this). |
81 |
|
* |
82 |
+ |
* This uses the uk.org.iscream.cms.util.FormatName class |
83 |
+ |
* to format the toString() |
84 |
+ |
* |
85 |
|
* @return the name of this class and its CVS revision |
86 |
|
*/ |
87 |
|
public String toString() { |
88 |
< |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
88 |
> |
return FormatName.getName( |
89 |
> |
_name, |
90 |
> |
getClass().getName(), |
91 |
> |
REVISION); |
92 |
|
} |
93 |
+ |
|
94 |
|
//---PRIVATE METHODS--- |
95 |
+ |
|
96 |
+ |
/** |
97 |
+ |
* This method is provided if this class wishes to log |
98 |
+ |
* a message itself. |
99 |
+ |
* |
100 |
+ |
* @param source A String representation of the source |
101 |
+ |
* @param verbosity the verbosity of this message |
102 |
+ |
* @param message The message to log |
103 |
+ |
*/ |
104 |
+ |
private void write(String source, int verbosity, String message) { |
105 |
+ |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
106 |
+ |
} |
107 |
|
|
108 |
|
//---ACCESSOR/MUTATOR METHODS--- |
109 |
|
|
110 |
|
//---ATTRIBUTES--- |
111 |
|
|
112 |
< |
/** |
113 |
< |
* A reference to the ScreenLogger we'll use |
114 |
< |
*/ |
115 |
< |
private LoggerImpl _screenlog; |
116 |
< |
|
117 |
< |
/** |
118 |
< |
* A reference to the FileLogger we'll use |
119 |
< |
*/ |
120 |
< |
private LoggerImpl _filelog; |
112 |
> |
/** |
113 |
> |
* A reference to the ScreenLogger we'll use |
114 |
> |
*/ |
115 |
> |
private LoggerImpl _screenlog; |
116 |
> |
|
117 |
> |
/** |
118 |
> |
* A reference to the FileLogger we'll use |
119 |
> |
*/ |
120 |
> |
private LoggerImpl _filelog; |
121 |
> |
|
122 |
> |
/** |
123 |
> |
* This is the friendly identifier of the |
124 |
> |
* component this class is running in. |
125 |
> |
* eg, a Filter may be called "filter1", |
126 |
> |
* If this class does not have an owning |
127 |
> |
* component, a name from the configuration |
128 |
> |
* can be placed here. This name could also |
129 |
> |
* be changed to null for utility classes. |
130 |
> |
*/ |
131 |
> |
private String _name = Core.NAME; |
132 |
|
|
133 |
|
//---STATIC ATTRIBUTES--- |
134 |
|
|
135 |
< |
} |
135 |
> |
} |