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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/loggers/ScreenLogger.java (file contents):
Revision 1.2 by ajm, Wed Nov 29 21:27:25 2000 UTC vs.
Revision 1.9 by tdb, Tue May 21 16:47:17 2002 UTC

# Line 1 | Line 1
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.ac.ukc.iscream.core.loggers;
22 > package uk.org.iscream.cms.server.core.loggers;
23  
24   //---IMPORTS---
25 < import uk.ac.ukc.iscream.core.LoggerImpl;
26 < import uk.ac.ukc.iscream.core.Logger;
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;
# Line 33 | Line 53 | public class ScreenLogger implements LoggerImpl {
53       * Creates a new ScreenLoggerServant.
54       */
55      public ScreenLogger() {
56 <        _verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity"));
37 <        write(this.toString(), Logger.SYSINIT, "started");
38 <        write(this.toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel);
56 >        write(toString(), Logger.SYSINIT, "started");
57      }
58  
59   //---PUBLIC METHODS---
60  
61      /**
62 <         * The write() method takes a message, formats it using the
63 <         * formatLogLine() method, and then outputs it to the screen
64 <         * using System.out.println(). The source is usually the
65 <         * calling object, referenced by `this'. The method has been
66 <         * made synchronized to avoid it being called by two different
67 <         * objects and the output ending up merged on the screen.
62 >         * The write() method takes a line of text, pre-formatted
63 >         * and outputs it using a method defined by the actual
64 >         * implementation. The verbosity is given in case the
65 >         * implementation wishes to utilise it in the layout -
66 >         * eg. a different colour or font.
67 >         *
68 >         * This instance simply prints the message to the screen.
69           *
70 <         * @param source A string representation of the calling object.
70 >         * @param line A line of formatted text to be logged
71           * @param verbosity the verbosity of this message
72 <         * @param message The text to be logged.
73 <         */  
74 <    public synchronized void write(String source, int verbosity, String message) {
56 <        if (verbosity <= _verbosityLevel) {
57 <                String line = formatLogLine(source, message);
58 <                System.out.println(line);
59 <        }
72 >         */  
73 >    public synchronized void write(String line, int verbosity) {;
74 >        System.out.println(line);
75      }
76        
77      /**
78       * Overrides the {@link java.lang.Object#toString() Object.toString()}
79       * method to provide clean logging (every class should have this).
80       *
81 +     * This uses the uk.org.iscream.cms.server.util.FormatName class
82 +     * to format the toString()
83 +     *
84       * @return the name of this class and its CVS revision
85       */
86      public String toString() {
87 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
88 <        //return "ScreenLogger" + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
87 >        return FormatName.getName(
88 >            _name,
89 >            getClass().getName(),
90 >            REVISION);
91      }
92 +    
93   //---PRIVATE METHODS---
94 <
95 <        /**
96 <         * This method generates a nicely formatted line for the log,
97 <         * including the date/time and the source of the message. The date
98 <         * and time are formatted using the DateFormat class, and the source
99 <         * class is formatted using the toString() method found in every
100 <         * source file. This is then prepended to the message and returned.
101 <         *
102 <         * @param source A string representation of the calling object.
103 <         * @param message The message to be logged.
104 <         * @return The string to be written to the log.
84 <         */
85 <    private String formatLogLine(String source, String message){
86 <        String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
87 <        return "[" + date + "] " + source + ": " + message;
94 >    
95 >    /**
96 >     * This method is provided if this class wishes to log
97 >     * a message itself.
98 >     *
99 >         * @param source A String representation of the source
100 >         * @param verbosity the verbosity of this message
101 >         * @param message The message to log
102 >         */  
103 >    private void write(String source, int verbosity, String message) {
104 >        write(FormatName.formatLogLine(source, verbosity, message), verbosity);
105      }
106  
107   //---ACCESSOR/MUTATOR METHODS---
108  
109   //---ATTRIBUTES---
110 <
111 <        /**
112 <         * The verbosity level of this instance
113 <         */
114 <        private int _verbosityLevel;
110 >    
111 >    /**
112 >     * This is the friendly identifier of the
113 >     * component this class is running in.
114 >     * eg, a Filter may be called "filter1",
115 >     * If this class does not have an owning
116 >     * component,  a name from the configuration
117 >     * can be placed here.  This name could also
118 >     * be changed to null for utility classes.
119 >     */
120 >    private String _name = Core.NAME;
121      
122   //---STATIC ATTRIBUTES---
123      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines