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.9
Committed: Sat May 18 18:16:01 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.8: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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