1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.org.iscream.cms.server.core; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.org.iscream.cms.server.util.*; |
6 |
|
7 |
/** |
8 |
* The LoggerServant is an implementation of the Logger defined |
9 |
* in the IDL interface. Allows classes to send logging information |
10 |
* over CORBA to a local implementation of the LoggerImpl interface. |
11 |
* |
12 |
* @author $Author: tdb1 $ |
13 |
* @version $Id: LoggerServant.java,v 1.9 2001/03/14 23:25:29 tdb1 Exp $ |
14 |
*/ |
15 |
class LoggerServant extends LoggerPOA { |
16 |
|
17 |
//---FINAL ATTRIBUTES--- |
18 |
|
19 |
/** |
20 |
* The current CVS revision of this class |
21 |
*/ |
22 |
public final String REVISION = "$Revision: 1.9 $"; |
23 |
|
24 |
/** |
25 |
* An array of names of verbosity levels. |
26 |
* Thus logging messages are now "classed" by the level" |
27 |
* This string is prepended to the "source" of a logging message. |
28 |
*/ |
29 |
public final static String[] VERBOSITY_NAMES = {"FATAL", "ERROR", "WARNING", "SYSMSG", "SYSINIT", "DEBUG"}; |
30 |
|
31 |
//---STATIC METHODS--- |
32 |
|
33 |
//---CONSTRUCTORS--- |
34 |
|
35 |
/** |
36 |
* Creates a new LoggerServant. |
37 |
* |
38 |
* @param logger a reference to the LoggerImpl this will use |
39 |
*/ |
40 |
public LoggerServant(LoggerImpl logger) { |
41 |
_logger = logger; |
42 |
_verbosityLevel = Integer.parseInt(System.getProperty("uk.org.iscream.cms.server.Verbosity")); |
43 |
write(toString(), Logger.SYSINIT, "started"); |
44 |
write(toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
45 |
} |
46 |
|
47 |
//---PUBLIC METHODS--- |
48 |
|
49 |
/** |
50 |
* The write() method takes a source, verbosity level and |
51 |
* message, and formats them using an external line |
52 |
* formatting method. This line is then given to the logger |
53 |
* to be written. Note that checking of the level is carried |
54 |
* out here. |
55 |
* |
56 |
* @param source A string representation of the calling object. |
57 |
* @param verbosity the verbosity of this message |
58 |
* @param message The text to be logged. |
59 |
*/ |
60 |
public void write(String source, int verbosity, String message) { |
61 |
if (verbosity <= _verbosityLevel) { |
62 |
_logger.write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
63 |
} |
64 |
} |
65 |
|
66 |
/** |
67 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
68 |
* method to provide clean logging (every class should have this). |
69 |
* |
70 |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
71 |
* to format the toString() |
72 |
* |
73 |
* @return the name of this class and its CVS revision |
74 |
*/ |
75 |
public String toString() { |
76 |
return FormatName.getName( |
77 |
_name, |
78 |
getClass().getName(), |
79 |
REVISION); |
80 |
} |
81 |
|
82 |
//---PRIVATE METHODS--- |
83 |
|
84 |
//---ACCESSOR/MUTATOR METHODS--- |
85 |
|
86 |
//---ATTRIBUTES--- |
87 |
|
88 |
/** |
89 |
* The verbosity level of this instance |
90 |
*/ |
91 |
private int _verbosityLevel; |
92 |
|
93 |
/** |
94 |
* The actual Logger used by this instance |
95 |
*/ |
96 |
private LoggerImpl _logger; |
97 |
|
98 |
/** |
99 |
* This is the friendly identifier of the |
100 |
* component this class is running in. |
101 |
* eg, a Filter may be called "filter1", |
102 |
* If this class does not have an owning |
103 |
* component, a name from the configuration |
104 |
* can be placed here. This name could also |
105 |
* be changed to null for utility classes. |
106 |
*/ |
107 |
private String _name = Core.NAME; |
108 |
|
109 |
//---STATIC ATTRIBUTES--- |
110 |
|
111 |
} |