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.8
Committed: Tue May 29 17:02:35 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.7: +7 -7 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

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