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