1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.core; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.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: ajm4 $ |
13 |
* @version $Id: LoggerServant.java,v 1.5 2001/02/23 19:02:55 ajm4 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.5 $"; |
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.ac.ukc.iscream.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 simply passes the call on to it's local |
51 |
* LoggerImpl object. |
52 |
* |
53 |
* Note the "source" is prepended with the name of the verbosity level. |
54 |
* |
55 |
* @param source A string representation of the calling object. |
56 |
* @param verbosity the verbosity of this message |
57 |
* @param message The text to be logged. |
58 |
*/ |
59 |
public void write(String source, int verbosity, String message) { |
60 |
if (verbosity <= _verbosityLevel) { |
61 |
_logger.write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
62 |
} |
63 |
} |
64 |
|
65 |
/** |
66 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
67 |
* method to provide clean logging (every class should have this). |
68 |
* |
69 |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
70 |
* to format the toString() |
71 |
* |
72 |
* @return the name of this class and its CVS revision |
73 |
*/ |
74 |
public String toString() { |
75 |
return FormatName.getName( |
76 |
_name, |
77 |
getClass().getName(), |
78 |
REVISION); |
79 |
} |
80 |
|
81 |
//---PRIVATE METHODS--- |
82 |
|
83 |
//---ACCESSOR/MUTATOR METHODS--- |
84 |
|
85 |
//---ATTRIBUTES--- |
86 |
|
87 |
/** |
88 |
* The verbosity level of this instance |
89 |
*/ |
90 |
private int _verbosityLevel; |
91 |
|
92 |
/** |
93 |
* The actual Logger used by this instance |
94 |
*/ |
95 |
private LoggerImpl _logger; |
96 |
|
97 |
/** |
98 |
* This is the friendly identifier of the |
99 |
* component this class is running in. |
100 |
* eg, a Filter may be called "filter1", |
101 |
* If this class does not have an owning |
102 |
* component, a name from the configuration |
103 |
* can be placed here. This name could also |
104 |
* be changed to null for utility classes. |
105 |
*/ |
106 |
private String _name = Core.NAME; |
107 |
|
108 |
//---STATIC ATTRIBUTES--- |
109 |
|
110 |
} |