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/SimpleGUILogger.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: +5 -3 lines
Log Message:
Update for package move.

File Contents

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