1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* 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 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.ac.ukc.iscream.core.loggers; |
22 |
> |
package uk.org.iscream.cms.server.core.loggers; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
26 |
< |
import uk.ac.ukc.iscream.core.*; |
25 |
> |
import uk.org.iscream.cms.server.util.*; |
26 |
> |
import uk.org.iscream.cms.server.core.*; |
27 |
|
import java.util.Date; |
28 |
|
import java.text.DateFormat; |
29 |
|
import java.util.Locale; |
53 |
|
* Creates a new ScreenLoggerServant. |
54 |
|
*/ |
55 |
|
public ScreenLogger() { |
36 |
– |
_verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")); |
56 |
|
write(toString(), Logger.SYSINIT, "started"); |
38 |
– |
write(toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
57 |
|
} |
58 |
|
|
59 |
|
//---PUBLIC METHODS--- |
60 |
|
|
61 |
|
/** |
62 |
< |
* The write() method takes a message, formats it using the |
63 |
< |
* formatLogLine() method, and then outputs it to the screen |
64 |
< |
* using System.out.println(). The source is usually the |
65 |
< |
* calling object, referenced by `this'. The method has been |
66 |
< |
* made synchronized to avoid it being called by two different |
67 |
< |
* objects and the output ending up merged on the screen. |
68 |
< |
* |
69 |
< |
* @param source A string representation of the calling object. |
70 |
< |
* @param verbosity the verbosity of this message |
71 |
< |
* @param message The text to be logged. |
72 |
< |
*/ |
73 |
< |
public synchronized void write(String source, int verbosity, String message) { |
74 |
< |
if (verbosity <= _verbosityLevel) { |
57 |
< |
String line = formatLogLine(source, message); |
58 |
< |
System.out.println(line); |
59 |
< |
} |
62 |
> |
* The write() method takes a line of text, pre-formatted |
63 |
> |
* and outputs it using a method defined by the actual |
64 |
> |
* implementation. The verbosity is given in case the |
65 |
> |
* implementation wishes to utilise it in the layout - |
66 |
> |
* eg. a different colour or font. |
67 |
> |
* |
68 |
> |
* This instance simply prints the message to the screen. |
69 |
> |
* |
70 |
> |
* @param line A line of formatted text to be logged |
71 |
> |
* @param verbosity the verbosity of this message |
72 |
> |
*/ |
73 |
> |
public synchronized void write(String line, int verbosity) {; |
74 |
> |
System.out.println(line); |
75 |
|
} |
76 |
|
|
77 |
|
/** |
78 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
79 |
|
* method to provide clean logging (every class should have this). |
80 |
|
* |
81 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
81 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
82 |
|
* to format the toString() |
83 |
|
* |
84 |
|
* @return the name of this class and its CVS revision |
91 |
|
} |
92 |
|
|
93 |
|
//---PRIVATE METHODS--- |
94 |
< |
|
94 |
> |
|
95 |
|
/** |
96 |
< |
* This method generates a nicely formatted line for the log, |
97 |
< |
* including the date/time and the source of the message. The date |
98 |
< |
* and time are formatted using the DateFormat class, and the source |
99 |
< |
* class is formatted using the toString() method found in every |
100 |
< |
* source file. This is then prepended to the message and returned. |
101 |
< |
* |
102 |
< |
* @param source A string representation of the calling object. |
103 |
< |
* @param message The message to be logged. |
104 |
< |
* @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; |
96 |
> |
* This method is provided if this class wishes to log |
97 |
> |
* a message itself. |
98 |
> |
* |
99 |
> |
* @param source A String representation of the source |
100 |
> |
* @param verbosity the verbosity of this message |
101 |
> |
* @param message The message to log |
102 |
> |
*/ |
103 |
> |
private void write(String source, int verbosity, String message) { |
104 |
> |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
105 |
|
} |
106 |
|
|
107 |
|
//---ACCESSOR/MUTATOR METHODS--- |
108 |
|
|
109 |
|
//---ATTRIBUTES--- |
99 |
– |
|
100 |
– |
/** |
101 |
– |
* The verbosity level of this instance |
102 |
– |
*/ |
103 |
– |
private int _verbosityLevel; |
110 |
|
|
111 |
|
/** |
112 |
|
* This is the friendly identifier of the |