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/SimpleSwingLogger.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/loggers/SimpleSwingLogger.java (file contents):
Revision 1.3 by ajm, Mon Nov 27 22:38:54 2000 UTC vs.
Revision 1.10 by tdb, Sat May 18 18:16:01 2002 UTC

# Line 1 | Line 1
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.ac.ukc.iscream.core.*;
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;
# Line 10 | Line 31 | import javax.swing.border.*;
31   import java.awt.Color;
32  
33   /**
34 < * The SimpleGUILogger is an implementation of the LoggerImpl defined
34 > * The SimpleSwingLogger 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$
47   * @version $Id$
48   */
49 < class SimpleSwingLogger extends JFrame implements LoggerImpl {
49 > public class SimpleSwingLogger extends JFrame implements LoggerImpl {
50  
51   //---FINAL ATTRIBUTES---
52  
# Line 39 | Line 66 | class SimpleSwingLogger extends JFrame implements Logg
66       * Creates a new Simple Swing Logger.
67       */
68      public SimpleSwingLogger() {
69 <        _verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity"));
69 >        _maxMessages = Integer.parseInt(System.getProperty("uk.org.iscream.cms.server.LoggerClass.SimpleSwingLogger.maxMessages"));
70          System.out.println(this.toString() + ": opening window");
71  
72          // set up the Frame
# Line 50 | Line 77 | class SimpleSwingLogger extends JFrame implements Logg
77          Box box = Box.createVerticalBox();
78  
79          // create the i-scream logo at the top
80 <        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
80 >        JLabel iscream = new JLabel(new ImageIcon("./uk/ac/ukc/iscream/core/loggers/i-scream.gif"));
81          JLabel comment = new JLabel("   I-Scream System Logging Console");
82          comment.setForeground( new Color(0, 0, 102));
83          iscream.setBackground(Color.white);
# Line 59 | Line 86 | class SimpleSwingLogger extends JFrame implements Logg
86          header.add(comment);
87          header.add(Box.createHorizontalGlue());
88          header.add(iscream);
62        //header.add(Box.createHorizontalGlue());
89  
90          // set up the text area
91          _textArea.setEditable(false);
# Line 74 | Line 100 | class SimpleSwingLogger extends JFrame implements Logg
100  
101          // show the window
102          show();
103 <        write(this.toString(), Logger.SYSINIT, "started");
78 <        write(this.toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel);
103 >        write(toString(), Logger.SYSINIT, "started");
104      }
105  
106   //---PUBLIC METHODS---
107  
108      /**
109 <     * The write() method takes a message, formats it using the
110 <     * formatLogLine() method, and then outputs it to the screen
111 <     * using the text area. The source is usually the
112 <     * calling object, referenced by `this'. The method has been
113 <     * made synchronized to avoid it being called by two different
114 <     * objects and the output ending up merged on the screen.
115 <     *
116 <     * @param source A string representation of the calling object.
117 <     * @param verbosity the verbosity of this message
118 <     * @param message The text to be logged.
119 <     */  
120 <    public synchronized void write(String source, int verbosity, String message) {
121 <        if (verbosity <= _verbosityLevel) {
122 <            String line = formatLogLine(source, message);
123 <            _textArea.insert(line + "\n",0);
99 <        }
109 >         * The write() method takes a line of text, pre-formatted
110 >         * and outputs it using a method defined by the actual
111 >         * implementation. The verbosity is given in case the
112 >         * implementation wishes to utilise it in the layout -
113 >         * eg. a different colour or font.
114 >         *
115 >         * This instance writes the line to a Swing based GUI
116 >         * logger.
117 >         *
118 >         * @param line A line of formatted text to be logged
119 >         * @param verbosity the verbosity of this message
120 >         */  
121 >    public synchronized void write(String line, int verbosity) {
122 >        _textArea.insert(line + "\n",0);
123 >        _textArea.setRows(_maxMessages);
124      }
125        
126      /**
127       * Overrides the {@link java.lang.Object#toString() Object.toString()}
128       * method to provide clean logging (every class should have this).
129       *
130 +     * This uses the uk.org.iscream.cms.server.util.FormatName class
131 +     * to format the toString()
132 +     *
133       * @return the name of this class and its CVS revision
134       */
135      public String toString() {
136 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
137 <        //return "ScreenLogger" + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
136 >        return FormatName.getName(
137 >            _name,
138 >            getClass().getName(),
139 >            REVISION);
140      }
141 +    
142   //---PRIVATE METHODS---
143  
144      /**
145 <     * This method generates a nicely formatted line for the log,
146 <     * including the date/time and the source of the message. The date
147 <     * and time are formatted using the DateFormat class, and the source
148 <     * class is formatted using the toString() method found in every
149 <     * source file. This is then prepended to the message and returned.
150 <     *
151 <     * @param source A string representation of the calling object.
152 <     * @param message The message to be logged.
153 <     * @return The string to be written to the log.
124 <     */
125 <    private String formatLogLine(String source, String message){
126 <        String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
127 <        return "[" + date + "] " + source + ": " + message;
145 >     * This method is provided if this class wishes to log
146 >     * a message itself.
147 >     *
148 >         * @param source A String representation of the source
149 >         * @param verbosity the verbosity of this message
150 >         * @param message The message to log
151 >         */  
152 >    private void write(String source, int verbosity, String message) {
153 >        write(FormatName.formatLogLine(source, verbosity, message), verbosity);
154      }
155  
156   //---ACCESSOR/MUTATOR METHODS---
# Line 135 | Line 161 | class SimpleSwingLogger extends JFrame implements Logg
161       * A text area to write log messages to
162       */
163      private JTextArea _textArea = new JTextArea();
164 <
139 <
164 >    
165      /**
166 <     * The verbosity level of this instance
166 >     * The maximum number of messages that can
167 >     * be displayed before bottom items are removed.
168 >     * This is needed to fix the memory overload problem
169 >     * that was seen when the GUI got too full!
170       */
171 <    private int _verbosityLevel;
171 >    private int _maxMessages;
172 >    
173 >    /**
174 >     * This is the friendly identifier of the
175 >     * component this class is running in.
176 >     * eg, a Filter may be called "filter1",
177 >     * If this class does not have an owning
178 >     * component,  a name from the configuration
179 >     * can be placed here.  This name could also
180 >     * be changed to null for utility classes.
181 >     */
182 >    private String _name = Core.NAME;
183      
184   //---STATIC ATTRIBUTES---
185      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines