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.2
Committed: Wed Nov 29 21:27:25 2000 UTC (23 years, 5 months ago) by ajm
Branch: MAIN
Branch point for: SERVER_PACKAGEBUILD
Changes since 1.1: +6 -4 lines
Log Message:
Update for package move.

File Contents

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