1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* http://www.i-scream.org.uk |
4 |
* 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 |
//---PACKAGE DECLARATION--- |
22 |
package uk.org.iscream.cms.server.core.loggers; |
23 |
|
24 |
//---IMPORTS--- |
25 |
import uk.org.iscream.cms.server.util.*; |
26 |
import uk.org.iscream.cms.server.core.*; |
27 |
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 |
* 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 |
* @author $Author: tdb $ |
48 |
* @version $Id: SimpleGUILogger.java,v 1.9 2002/05/18 18:16:01 tdb Exp $ |
49 |
*/ |
50 |
public class SimpleGUILogger implements LoggerImpl { |
51 |
|
52 |
//---FINAL ATTRIBUTES--- |
53 |
|
54 |
/** |
55 |
* The current CVS revision of this class |
56 |
*/ |
57 |
public final String REVISION = "$Revision: 1.9 $"; |
58 |
|
59 |
//---STATIC METHODS--- |
60 |
|
61 |
//---CONSTRUCTORS--- |
62 |
|
63 |
/** |
64 |
* Creates a new ScreenLoggerServant. |
65 |
*/ |
66 |
public SimpleGUILogger() { |
67 |
_maxMessages = Integer.parseInt(System.getProperty("uk.org.iscream.cms.server.LoggerClass.SimpleGUILogger.maxMessages")); |
68 |
|
69 |
getFrame().add(getTextArea()); |
70 |
getFrame().setSize(500,500); |
71 |
getFrame().setVisible(true); |
72 |
|
73 |
write(toString(), Logger.SYSINIT, "started"); |
74 |
} |
75 |
|
76 |
//---PUBLIC METHODS--- |
77 |
|
78 |
/** |
79 |
* 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 |
* |
85 |
* 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 |
* @param verbosity the verbosity of this message |
90 |
*/ |
91 |
public synchronized void write(String line, int verbosity) { |
92 |
getTextArea().append(line + "\n"); |
93 |
getTextArea().setRows(_maxMessages); |
94 |
} |
95 |
|
96 |
/** |
97 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
98 |
* method to provide clean logging (every class should have this). |
99 |
* |
100 |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
101 |
* to format the toString() |
102 |
* |
103 |
* @return the name of this class and its CVS revision |
104 |
*/ |
105 |
public String toString() { |
106 |
return FormatName.getName( |
107 |
_name, |
108 |
getClass().getName(), |
109 |
REVISION); |
110 |
} |
111 |
|
112 |
//---PRIVATE METHODS--- |
113 |
|
114 |
/** |
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 |
private void write(String source, int verbosity, String message) { |
123 |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
124 |
} |
125 |
|
126 |
//---ACCESSOR/MUTATOR METHODS--- |
127 |
|
128 |
/** |
129 |
* An accessor for the frame |
130 |
* |
131 |
* @return the frame for this class |
132 |
*/ |
133 |
private Frame getFrame(){ |
134 |
return frame; |
135 |
} |
136 |
|
137 |
/** |
138 |
* an accessor for the text area |
139 |
* |
140 |
* @return the text area |
141 |
*/ |
142 |
private TextArea getTextArea(){ |
143 |
return textArea; |
144 |
} |
145 |
|
146 |
//---ATTRIBUTES--- |
147 |
|
148 |
/** |
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 |
|
177 |
//---STATIC ATTRIBUTES--- |
178 |
|
179 |
} |