1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.core.loggers; |
2 |
> |
package uk.org.iscream.cms.server.core.loggers; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
> |
import uk.org.iscream.cms.server.util.*; |
6 |
> |
import uk.org.iscream.cms.server.core.*; |
7 |
|
import java.util.Date; |
8 |
|
import java.text.DateFormat; |
9 |
|
import java.util.Locale; |
33 |
|
* Creates a new ScreenLoggerServant. |
34 |
|
*/ |
35 |
|
public ScreenLogger() { |
36 |
– |
_verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")); |
36 |
|
write(toString(), Logger.SYSINIT, "started"); |
38 |
– |
write(toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
37 |
|
} |
38 |
|
|
39 |
|
//---PUBLIC METHODS--- |
40 |
|
|
41 |
|
/** |
42 |
< |
* The write() method takes a message, formats it using the |
43 |
< |
* formatLogLine() method, and then outputs it to the screen |
44 |
< |
* using System.out.println(). The source is usually the |
45 |
< |
* calling object, referenced by `this'. The method has been |
46 |
< |
* made synchronized to avoid it being called by two different |
47 |
< |
* objects and the output ending up merged on the screen. |
48 |
< |
* |
49 |
< |
* @param source A string representation of the calling object. |
50 |
< |
* @param verbosity the verbosity of this message |
51 |
< |
* @param message The text to be logged. |
52 |
< |
*/ |
53 |
< |
public synchronized void write(String source, int verbosity, String message) { |
54 |
< |
if (verbosity <= _verbosityLevel) { |
57 |
< |
String line = formatLogLine(source, message); |
58 |
< |
System.out.println(line); |
59 |
< |
} |
42 |
> |
* The write() method takes a line of text, pre-formatted |
43 |
> |
* and outputs it using a method defined by the actual |
44 |
> |
* implementation. The verbosity is given in case the |
45 |
> |
* implementation wishes to utilise it in the layout - |
46 |
> |
* eg. a different colour or font. |
47 |
> |
* |
48 |
> |
* This instance simply prints the message to the screen. |
49 |
> |
* |
50 |
> |
* @param line A line of formatted text to be logged |
51 |
> |
* @param verbosity the verbosity of this message |
52 |
> |
*/ |
53 |
> |
public synchronized void write(String line, int verbosity) {; |
54 |
> |
System.out.println(line); |
55 |
|
} |
56 |
|
|
57 |
|
/** |
58 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
59 |
|
* method to provide clean logging (every class should have this). |
60 |
|
* |
61 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
61 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
62 |
|
* to format the toString() |
63 |
|
* |
64 |
|
* @return the name of this class and its CVS revision |
71 |
|
} |
72 |
|
|
73 |
|
//---PRIVATE METHODS--- |
74 |
< |
|
74 |
> |
|
75 |
|
/** |
76 |
< |
* This method generates a nicely formatted line for the log, |
77 |
< |
* including the date/time and the source of the message. The date |
78 |
< |
* and time are formatted using the DateFormat class, and the source |
79 |
< |
* class is formatted using the toString() method found in every |
80 |
< |
* source file. This is then prepended to the message and returned. |
81 |
< |
* |
82 |
< |
* @param source A string representation of the calling object. |
83 |
< |
* @param message The message to be logged. |
84 |
< |
* @return The string to be written to the log. |
90 |
< |
*/ |
91 |
< |
private String formatLogLine(String source, String message){ |
92 |
< |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date()); |
93 |
< |
return "[" + date + "] " + source + ": " + message; |
76 |
> |
* This method is provided if this class wishes to log |
77 |
> |
* a message itself. |
78 |
> |
* |
79 |
> |
* @param source A String representation of the source |
80 |
> |
* @param verbosity the verbosity of this message |
81 |
> |
* @param message The message to log |
82 |
> |
*/ |
83 |
> |
private void write(String source, int verbosity, String message) { |
84 |
> |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
85 |
|
} |
86 |
|
|
87 |
|
//---ACCESSOR/MUTATOR METHODS--- |
88 |
|
|
89 |
|
//---ATTRIBUTES--- |
99 |
– |
|
100 |
– |
/** |
101 |
– |
* The verbosity level of this instance |
102 |
– |
*/ |
103 |
– |
private int _verbosityLevel; |
90 |
|
|
91 |
|
/** |
92 |
|
* This is the friendly identifier of the |