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.8 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.ac.ukc.iscream.core.loggers;
21 > package uk.org.iscream.cms.server.core.loggers;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.core.LoggerImpl;
25 < import uk.ac.ukc.iscream.core.Logger;
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 33 | Line 52 | public class ScreenLogger implements LoggerImpl {
52       * Creates a new ScreenLoggerServant.
53       */
54      public ScreenLogger() {
55 <        _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);
55 >        write(toString(), Logger.SYSINIT, "started");
56      }
57  
58   //---PUBLIC METHODS---
59  
60      /**
61 <         * The write() method takes a message, formats it using the
62 <         * formatLogLine() method, and then outputs it to the screen
63 <         * using System.out.println(). The source is usually the
64 <         * calling object, referenced by `this'. The method has been
65 <         * made synchronized to avoid it being called by two different
66 <         * objects and the output ending up merged on the screen.
61 >         * The write() method takes a line of text, pre-formatted
62 >         * and outputs it using a method defined by the actual
63 >         * implementation. The verbosity is given in case the
64 >         * implementation wishes to utilise it in the layout -
65 >         * eg. a different colour or font.
66 >         *
67 >         * This instance simply prints the message to the screen.
68           *
69 <         * @param source A string representation of the calling object.
69 >         * @param line A line of formatted text to be logged
70           * @param verbosity the verbosity of this message
71 <         * @param message The text to be logged.
72 <         */  
73 <    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 <        }
71 >         */  
72 >    public synchronized void write(String line, int verbosity) {;
73 >        System.out.println(line);
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 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.
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;
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   //---ATTRIBUTES---
109 <
110 <        /**
111 <         * The verbosity level of this instance
112 <         */
113 <        private int _verbosityLevel;
109 >    
110 >    /**
111 >     * This is the friendly identifier of the
112 >     * component this class is running in.
113 >     * eg, a Filter may be called "filter1",
114 >     * If this class does not have an owning
115 >     * component,  a name from the configuration
116 >     * can be placed here.  This name could also
117 >     * be changed to null for utility classes.
118 >     */
119 >    private String _name = Core.NAME;
120      
121   //---STATIC ATTRIBUTES---
122      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines