1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
< |
import org.omg.CORBA.*; |
6 |
< |
import org.omg.PortableServer.*; |
5 |
> |
import uk.ac.ukc.iscream.util.*; |
6 |
|
|
7 |
|
/** |
8 |
< |
* The ScreenLoggerServant is an implementation of the Logger defined |
9 |
< |
* in the IDL interface. It's only purpose is to simply print all the |
10 |
< |
* logging information it receives to the screen. |
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$ |
13 |
|
* @version $Id$ |
21 |
|
*/ |
22 |
|
public final String REVISION = "$Revision$"; |
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--- |
40 |
|
public LoggerServant(LoggerImpl logger) { |
41 |
|
_logger = logger; |
42 |
|
_verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")); |
43 |
< |
write(this.toString(), Logger.SYSINIT, "started"); |
44 |
< |
write(this.toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
43 |
> |
write(toString(), Logger.SYSINIT, "started"); |
44 |
> |
write(toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
45 |
|
} |
46 |
|
|
47 |
|
//---PUBLIC METHODS--- |
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 |
< |
_logger.write(source, verbosity, message); |
60 |
> |
_logger.write("[" + VERBOSITY_NAMES[verbosity] + "] " + source, verbosity, message); |
61 |
|
} |
62 |
|
|
63 |
|
/** |
64 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
65 |
|
* method to provide clean logging (every class should have this). |
66 |
< |
* |
67 |
< |
* This case returns the information from the LoggerImpl, although maybe |
68 |
< |
* it should be merged with this somehow ? |
69 |
< |
* |
66 |
> |
* |
67 |
> |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
68 |
> |
* to format the toString() |
69 |
> |
* |
70 |
|
* @return the name of this class and its CVS revision |
71 |
|
*/ |
72 |
|
public String toString() { |
73 |
< |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
73 |
> |
return FormatName.getName( |
74 |
> |
_name, |
75 |
> |
getClass().getName(), |
76 |
> |
REVISION); |
77 |
|
} |
78 |
+ |
|
79 |
|
//---PRIVATE METHODS--- |
80 |
|
|
81 |
|
//---ACCESSOR/MUTATOR METHODS--- |
91 |
|
* The actual Logger used by this instance |
92 |
|
*/ |
93 |
|
private LoggerImpl _logger; |
94 |
+ |
|
95 |
+ |
/** |
96 |
+ |
* This is the friendly identifier of the |
97 |
+ |
* component this class is running in. |
98 |
+ |
* eg, a Filter may be called "filter1", |
99 |
+ |
* If this class does not have an owning |
100 |
+ |
* component, a name from the configuration |
101 |
+ |
* can be placed here. This name could also |
102 |
+ |
* be changed to null for utility classes. |
103 |
+ |
*/ |
104 |
+ |
private String _name = Core.NAME; |
105 |
|
|
106 |
|
//---STATIC ATTRIBUTES--- |
107 |
|
|