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.11
Committed: Wed Feb 5 16:43:47 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.10: +5 -5 lines
Log Message:
Changed the server to use the external util package. Quite a minor change,
but does affect a lot of files.

File Contents

# User Rev Content
1 tdb 1.9 /*
2     * i-scream central monitoring system
3 tdb 1.10 * http://www.i-scream.org.uk
4 tdb 1.9 * 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 ajm 1.1 //---PACKAGE DECLARATION---
22 tdb 1.8 package uk.org.iscream.cms.server.core.loggers;
23 ajm 1.1
24     //---IMPORTS---
25 tdb 1.11 import uk.org.iscream.cms.util.*;
26 tdb 1.8 import uk.org.iscream.cms.server.core.*;
27 ajm 1.1 import java.util.Date;
28     import java.text.DateFormat;
29     import java.util.Locale;
30     import java.awt.Frame;
31     import java.awt.TextArea;
32     import java.awt.GridLayout;
33    
34     /**
35     * The SimpleGUILogger is an implementation of the LoggerImpl defined
36     * in the associated interface. It's only purpose is to simply print
37     * all the logging information it receives to a window frame.
38     *
39     * All very simple really...
40     *
41 ajm 1.3 * This class does have the problem that if too many messages are
42     * entered into the text area, then it will fill the memory of
43     * the JVM. This MAY have been fixed by adding the setRows(int)
44     * in the write(string) method, however the Java API does not
45     * specify if this enforces the max rows, but I THINK it does.
46     *
47 tdb 1.9 * @author $Author: tdb $
48 tdb 1.11 * @version $Id: SimpleGUILogger.java,v 1.10 2002/05/21 16:47:17 tdb Exp $
49 ajm 1.1 */
50 tdb 1.4 public class SimpleGUILogger implements LoggerImpl {
51 ajm 1.1
52     //---FINAL ATTRIBUTES---
53    
54     /**
55     * The current CVS revision of this class
56     */
57 tdb 1.11 public final String REVISION = "$Revision: 1.10 $";
58 ajm 1.1
59     //---STATIC METHODS---
60    
61     //---CONSTRUCTORS---
62    
63     /**
64     * Creates a new ScreenLoggerServant.
65     */
66     public SimpleGUILogger() {
67 tdb 1.8 _maxMessages = Integer.parseInt(System.getProperty("uk.org.iscream.cms.server.LoggerClass.SimpleGUILogger.maxMessages"));
68 ajm 1.1
69     getFrame().add(getTextArea());
70     getFrame().setSize(500,500);
71     getFrame().setVisible(true);
72    
73 ajm 1.3 write(toString(), Logger.SYSINIT, "started");
74 ajm 1.1 }
75    
76     //---PUBLIC METHODS---
77    
78     /**
79 tdb 1.6 * The write() method takes a line of text, pre-formatted
80     * and outputs it using a method defined by the actual
81     * implementation. The verbosity is given in case the
82     * implementation wishes to utilise it in the layout -
83     * eg. a different colour or font.
84 ajm 1.1 *
85 tdb 1.6 * This instance writes the line to a simple GUI message
86     * window.
87     *
88     * @param line A line of formatted text to be logged
89 ajm 1.1 * @param verbosity the verbosity of this message
90 tdb 1.6 */
91 tdb 1.5 public synchronized void write(String line, int verbosity) {
92     getTextArea().append(line + "\n");
93     getTextArea().setRows(_maxMessages);
94 ajm 1.1 }
95    
96 ajm 1.3 /**
97 ajm 1.1 * Overrides the {@link java.lang.Object#toString() Object.toString()}
98     * method to provide clean logging (every class should have this).
99     *
100 tdb 1.11 * This uses the uk.org.iscream.cms.util.FormatName class
101 ajm 1.3 * to format the toString()
102     *
103 ajm 1.1 * @return the name of this class and its CVS revision
104     */
105     public String toString() {
106 ajm 1.3 return FormatName.getName(
107     _name,
108     getClass().getName(),
109     REVISION);
110 ajm 1.1 }
111 ajm 1.3
112 ajm 1.1 //---PRIVATE METHODS---
113    
114 tdb 1.6 /**
115     * This method is provided if this class wishes to log
116     * a message itself.
117     *
118     * @param source A String representation of the source
119     * @param verbosity the verbosity of this message
120     * @param message The message to log
121     */
122 tdb 1.5 private void write(String source, int verbosity, String message) {
123     write(FormatName.formatLogLine(source, verbosity, message), verbosity);
124 ajm 1.1 }
125    
126     //---ACCESSOR/MUTATOR METHODS---
127    
128 ajm 1.3 /**
129     * An accessor for the frame
130     *
131     * @return the frame for this class
132     */
133 ajm 1.1 private Frame getFrame(){
134     return frame;
135     }
136    
137 ajm 1.3 /**
138     * an accessor for the text area
139     *
140     * @return the text area
141     */
142 ajm 1.1 private TextArea getTextArea(){
143     return textArea;
144     }
145    
146     //---ATTRIBUTES---
147 tdb 1.5
148 ajm 1.3 /**
149     * a frame
150     */
151     private Frame frame = new Frame("I-SCREAM LOGGER");
152    
153     /**
154     * a text area
155     */
156     private TextArea textArea = new TextArea(100,100);
157    
158     /**
159     * This is the friendly identifier of the
160     * component this class is running in.
161     * eg, a Filter may be called "filter1",
162     * If this class does not have an owning
163     * component, a name from the configuration
164     * can be placed here. This name could also
165     * be changed to null for utility classes.
166     */
167     private String _name = Core.NAME;
168    
169     /**
170     * The maximum number of messages that can
171     * be displayed before bottom items are removed.
172     * This is needed to fix the memory overload problem
173     * that was seen when the GUI got too full!
174     */
175     private int _maxMessages;
176 ajm 1.1
177     //---STATIC ATTRIBUTES---
178    
179 tdb 1.11 }