1 |
tdb |
1.9 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.12 |
* http://www.i-scream.org |
4 |
tdb |
1.9 |
* 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 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
22 |
tdb |
1.8 |
package uk.org.iscream.cms.server.core.loggers; |
23 |
tdb |
1.1 |
|
24 |
|
|
//---IMPORTS--- |
25 |
tdb |
1.11 |
import uk.org.iscream.cms.util.*; |
26 |
tdb |
1.8 |
import uk.org.iscream.cms.server.core.*; |
27 |
tdb |
1.1 |
import java.io.IOException; |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* The MultiLogger is just a gateway to both the ScreenLogger |
31 |
|
|
* and the FileLogger. |
32 |
|
|
* |
33 |
tdb |
1.9 |
* @author $Author: tdb $ |
34 |
tdb |
1.12 |
* @version $Id: MultiLogger.java,v 1.11 2003/02/05 16:43:47 tdb Exp $ |
35 |
tdb |
1.1 |
*/ |
36 |
tdb |
1.4 |
public class MultiLogger implements LoggerImpl { |
37 |
tdb |
1.1 |
|
38 |
|
|
//---FINAL ATTRIBUTES--- |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* The current CVS revision of this class |
42 |
|
|
*/ |
43 |
tdb |
1.12 |
public final String REVISION = "$Revision: 1.11 $"; |
44 |
tdb |
1.1 |
|
45 |
|
|
//---STATIC METHODS--- |
46 |
|
|
|
47 |
|
|
//---CONSTRUCTORS--- |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* Creates a new MultiLogger. |
51 |
|
|
*/ |
52 |
|
|
public MultiLogger() throws IOException { |
53 |
ajm |
1.3 |
_screenlog = new ScreenLogger(); |
54 |
|
|
_filelog = new FileLogger(); |
55 |
|
|
write(toString(), Logger.SYSINIT, "started"); |
56 |
tdb |
1.1 |
} |
57 |
|
|
|
58 |
|
|
//---PUBLIC METHODS--- |
59 |
|
|
|
60 |
|
|
/** |
61 |
tdb |
1.6 |
* 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 |
|
|
* 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 |
|
|
*/ |
73 |
tdb |
1.5 |
public synchronized void write(String line, int verbosity) { |
74 |
|
|
_screenlog.write(line, verbosity); |
75 |
|
|
_filelog.write(line, verbosity); |
76 |
tdb |
1.1 |
} |
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 |
tdb |
1.11 |
* This uses the uk.org.iscream.cms.util.FormatName class |
83 |
ajm |
1.3 |
* to format the toString() |
84 |
|
|
* |
85 |
tdb |
1.1 |
* @return the name of this class and its CVS revision |
86 |
|
|
*/ |
87 |
|
|
public String toString() { |
88 |
ajm |
1.3 |
return FormatName.getName( |
89 |
|
|
_name, |
90 |
|
|
getClass().getName(), |
91 |
|
|
REVISION); |
92 |
tdb |
1.1 |
} |
93 |
ajm |
1.3 |
|
94 |
tdb |
1.1 |
//---PRIVATE METHODS--- |
95 |
tdb |
1.6 |
|
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 |
tdb |
1.5 |
private void write(String source, int verbosity, String message) { |
105 |
|
|
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
106 |
|
|
} |
107 |
tdb |
1.1 |
|
108 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
109 |
|
|
|
110 |
|
|
//---ATTRIBUTES--- |
111 |
|
|
|
112 |
ajm |
1.3 |
/** |
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 |
tdb |
1.1 |
|
133 |
|
|
//---STATIC ATTRIBUTES--- |
134 |
|
|
|
135 |
tdb |
1.11 |
} |