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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/loggers/SimpleGUILogger.java (file contents):
Revision 1.2 by ajm, Wed Nov 29 21:27:25 2000 UTC vs.
Revision 1.7 by tdb, Wed Mar 14 23:25:29 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.core.loggers;
2 > package uk.org.iscream.core.loggers;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.core.LoggerImpl;
6 < import uk.ac.ukc.iscream.core.Logger;
5 > import uk.org.iscream.util.*;
6 > import uk.org.iscream.core.*;
7   import java.util.Date;
8   import java.text.DateFormat;
9   import java.util.Locale;
# Line 18 | Line 18 | import java.awt.GridLayout;
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$
28   * @version $Id$
29   */
30 < class SimpleGUILogger implements LoggerImpl {
30 > public class SimpleGUILogger implements LoggerImpl {
31  
32   //---FINAL ATTRIBUTES---
33  
# Line 38 | Line 44 | class SimpleGUILogger implements LoggerImpl {
44       * Creates a new ScreenLoggerServant.
45       */
46      public SimpleGUILogger() {
47 <        _verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity"));
47 >        _maxMessages = Integer.parseInt(System.getProperty("uk.org.iscream.LoggerClass.SimpleGUILogger.maxMessages"));
48          
49          getFrame().add(getTextArea());
50          getFrame().setSize(500,500);
51          getFrame().setVisible(true);
52          
53 <        write(this.toString(), Logger.SYSINIT, "started");
48 <        write(this.toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel);
53 >        write(toString(), Logger.SYSINIT, "started");
54      }
55  
56   //---PUBLIC METHODS---
57  
58      /**
59 <         * The write() method takes a message, formats it using the
60 <         * formatLogLine() method, and then outputs it to the screen
61 <         * using System.out.println(). The source is usually the
62 <         * calling object, referenced by `this'. The method has been
63 <         * made synchronized to avoid it being called by two different
59 <         * objects and the output ending up merged on the screen.
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 <         * @param source A string representation of the calling object.
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 <         * @param message The text to be logged.
71 <         */  
72 <    public synchronized void write(String source, int verbosity, String message) {
73 <        if (verbosity <= _verbosityLevel) {
67 <                String line = formatLogLine(source, message);
68 <                getTextArea().append(line + "\n");
69 <        }
70 >         */  
71 >    public synchronized void write(String line, int verbosity) {
72 >        getTextArea().append(line + "\n");
73 >        getTextArea().setRows(_maxMessages);
74      }
75        
76 <    /**
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.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 this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
87 <        //return "ScreenLogger" + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
86 >        return FormatName.getName(
87 >            _name,
88 >            getClass().getName(),
89 >            REVISION);
90      }
91 +    
92   //---PRIVATE METHODS---
93  
94 <        /**
95 <         * This method generates a nicely formatted line for the log,
96 <         * including the date/time and the source of the message. The date
97 <         * and time are formatted using the DateFormat class, and the source
98 <         * class is formatted using the toString() method found in every
99 <         * source file. This is then prepended to the message and returned.
100 <         *
101 <         * @param source A string representation of the calling object.
102 <         * @param message The message to be logged.
103 <         * @return The string to be written to the log.
94 <         */
95 <    private String formatLogLine(String source, String message){
96 <        String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
97 <        return "[" + date + "] " + source + ": " + message;
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 <    // an accessor for the frame
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 <    // an accessor for the text area
117 >    /**
118 >     * an accessor for the text area
119 >     *
120 >     * @return the text area
121 >     */
122      private TextArea getTextArea(){
123          return textArea;
124      }
125  
112    // class attributes:
113    // a frame
114    private Frame frame = new Frame("I-SCREAM CORE LOGGER");
115
116    // a text area
117    private TextArea textArea = new TextArea(100,100);
118
126   //---ATTRIBUTES---
127 +  
128 +    /**
129 +     * a frame
130 +     */
131 +    private Frame frame = new Frame("I-SCREAM LOGGER");
132  
133 <        /**
134 <         * The verbosity level of this instance
135 <         */
136 <        private int _verbosityLevel;
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      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines