ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/loggers/ScreenLogger.java
Revision: 1.1
Committed: Mon Nov 20 18:34:56 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Log Message:
New ScreenLogger. Does exactly the same, but implements a Java interface instead.
No CORBA functionality is present in this class, instead it is used by the new
LoggerServant.
Also added new method of acquiring the verbosity directly from the configuration
 system.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4     import uk.ac.ukc.iscream.core.*;
5     import java.util.Date;
6     import java.text.DateFormat;
7     import java.util.Locale;
8    
9     /**
10     * The ScreenLogger is an implementation of the LoggerImpl defined
11     * in the associated interface. It's only purpose is to simply print
12     * all the logging information it receives to the screen.
13     *
14     * @author $Author$
15     * @version $Id$
16     */
17     class ScreenLogger implements LoggerImpl {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24     public final String REVISION = "$Revision: 1.1 $";
25    
26     //---STATIC METHODS---
27    
28     //---CONSTRUCTORS---
29    
30     /**
31     * Creates a new ScreenLoggerServant.
32     */
33     public ScreenLogger() {
34     _verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity"));
35     write(this.toString(), Logger.SYSINIT, "started");
36     write(this.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) {
55     String line = formatLogLine(source, message);
56     System.out.println(line);
57     }
58     }
59    
60     /**
61     * Overrides the {@link java.lang.Object#toString() Object.toString()}
62     * method to provide clean logging (every class should have this).
63     *
64     * @return the name of this class and its CVS revision
65     */
66     public String toString() {
67     return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
68     //return "ScreenLogger" + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
69     }
70     //---PRIVATE METHODS---
71    
72     /**
73     * This method generates a nicely formatted line for the log,
74     * including the date/time and the source of the message. The date
75     * and time are formatted using the DateFormat class, and the source
76     * class is formatted using the toString() method found in every
77     * source file. This is then prepended to the message and returned.
78     *
79     * @param source A string representation of the calling object.
80     * @param message The message to be logged.
81     * @return The string to be written to the log.
82     */
83     private String formatLogLine(String source, String message){
84     String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
85     return "[" + date + "] " + source + ": " + message;
86     }
87    
88     //---ACCESSOR/MUTATOR METHODS---
89    
90     //---ATTRIBUTES---
91    
92     /**
93     * The verbosity level of this instance
94     */
95     private int _verbosityLevel;
96    
97     //---STATIC ATTRIBUTES---
98    
99     }