KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > logging > Logger


1 /**
2
3     Copyright (C) 2002-2003 Together
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library 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 GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19  Logger.java
20  Date: 02.12.2003.
21  @version 1.0.0
22  @authors:
23  Milosevic Sinisa sinisa@prozone.co.yu
24  Radoslav Dutina rale@prozone.co.yu
25  Zoran Milakovic zoran@prozone.co.yu
26  */

27 package org.webdocwf.util.loader.logging;
28
29 import java.io.IOException JavaDoc;
30
31
32 /**
33  * A general-purpose logging facility. It is modeled after
34  * <CODE>syslogd</CODE>. This is a base class from which an actual
35  * implementation is derived. It only defines how log message are written
36  * by a client. Where the log message is written and the mechanism for
37  * controlling logging is left up to the implementation. This class does
38  * not define any of these mechanism and their definition is not necessary
39  * for understand how to use this class. <P>
40  *
41  * Each log message is associate with a facility and has a level assigned
42  * to it. A facility is a symbolic (String) name that defines a class of
43  * log messages. A level is used to indicate the
44  *
45  It is expected that the implementation can enable, disable and
46  * direct log messages based on these attributes. Facilities and levels
47  * are defined symbolicly, with no restriction on the name, and form a tuple.
48  * Several standard levels are defined as integer constants and their use
49  * is expected to be higher performing than symbolic levels..<P>
50  *
51  *
52  *Normally, a single,
53  global instance of the object
54  * is exists and is obtainable by a static method in this class.<P>
55  *
56  * Log messages are written via an object implementing <CODE>LogChannel</CODE>.
57  * A channel is associated with a single facility, with the level being
58  * specified when a message is written. Normally, a <CODE>LogChannel</CODE>
59  * is obtained once at initialization time and use repeatedly. It is
60  * permissible to obtain multiple references to the log channel for a facility,
61  * but this is discouraged for performance reasons.<P>
62  *
63  * Log messages, even debugging ones, should be defined with care. They
64  * should be terse, but clear to someone who isn't intimately familiar with
65  * the code. Permanent debugging messages should be designed with the idea
66  * of use when supportting a deployed product.<P>
67  *
68  * The central logging object needs to be configured very early in the startup
69  * process. If logging can't be configured, then the startup should be aborted
70  * or a object created that does some simple form of logging, such as write
71  * to <CODE>stderr<CODE>. A client should never have to check if the global
72  * logger object exists.<P>
73  *
74  */

75 public abstract class Logger {
76
77     /**
78      * Standard level.
79      */

80     public static final int LOGMODE_NORMAL = 1;
81
82     /**
83      * A condition that should be corrected immediately
84      */

85     public static final int LOGMODE_NONE = 0;
86
87     /**
88      * Critical conditions.
89      */

90     public static final int LOGMODE_FULL = 2;
91
92     public static final String JavaDoc strLOGMODE_NONE = "NONE";
93     public static final String JavaDoc strLOGMODE_NORMAL = "NORMAL";
94     public static final String JavaDoc strLOGMODE_FULL = "FULL";
95
96     public boolean[] enbledLogLevels;
97
98     /**
99      * Global <CODE>Logger</CODE> object.
100      */

101     protected static Logger centralLogger;
102
103     /**
104      * Table of standard level names
105      */

106     protected static final String JavaDoc[] standardLevelNames = {
107         strLOGMODE_NORMAL, // 0
108
strLOGMODE_NONE, // 1
109
strLOGMODE_FULL // 2
110
};
111
112     /**
113      * Get the central (global) logging object.
114      *
115      * @return A reference the object. If the facility has not been
116      * initialized <CODE>null</CODE> is returned. However, this is
117      * considered a bug in the design of the initialization. Clients
118      * do not need to check for <CODE>null</CODE>.
119      */

120     public static Logger getCentralLogger() {
121         return centralLogger;
122     }
123
124     /**
125      * Configure Logger with given config file, interpreting of config file is
126      * logger implementation specific.
127      *
128      * @param confFilePath Path to configuration file.
129      * @throws Exception
130      */

131     abstract public void configure(String JavaDoc confFilePath) throws Exception JavaDoc;
132
133     /**
134      * Determine if logging is enabled for the specified level. This
135      * is useful to prevent a series of unnecessary logging calls,
136      * as often encountered with debug logging, or a call where generating
137      * the message is expensive.
138      *
139      * @param level Numeric level that is to be checked.
140      * @return <CODE>true</CODE> if enabled, <CODE>false</CODE> if not
141      * enabled.
142      */

143     abstract public boolean isEnabled(int level);
144
145     /**
146      * Determine if logging is enabled for the specified level. This
147      * is useful to prevent a series of unnecessary logging calls,
148      * as often encountered with debug logging, or a call where generating
149      * the message is expensive.
150      *
151      * @param level Symbolic level that is to be checked.
152      * @return <CODE>true</CODE> if enabled, <CODE>false</CODE> if not
153      * enabled.
154      */

155     abstract public boolean isEnabled(String JavaDoc level);
156
157     /**
158      * Convert a symbolic level to an integer identifier.
159      *
160      * @param level Symbolic level to convert
161      * @return The numeric level identifier
162      */

163     abstract public int getLevel(String JavaDoc level);
164
165
166     /**
167      * Write a string to the log file.
168      *
169      * @param level Numeric level the message is associated with.
170      * @param msg The message to log.
171      */

172     abstract public void write(int level, String JavaDoc msg);
173
174     /**
175      * Write a string to the log file.
176      *
177      * @param level Symbolic level the message is associated with.
178      * @param msg The message to log.
179      */

180     abstract public void write(String JavaDoc level, String JavaDoc msg);
181
182     /**
183      * Write a string and exception to the log file.
184      *
185      * @param level Numeric level the message is associated with.
186      * @param msg The message to log.
187      * @param throwable Exception or error to log.
188      */

189     abstract public void write(int level, String JavaDoc msg, Throwable JavaDoc throwable);
190
191     /**
192      * Write a string and exception to the log file.
193      *
194      * @param level Symbolic level the message is associated with.
195      * @param msg The message to log.
196      * @param throwable Exception or error to log.
197      */

198     abstract public void write(String JavaDoc level, String JavaDoc msg, Throwable JavaDoc throwable);
199
200     abstract public boolean[] getEnabledLogLevels();
201
202     abstract public void setEnabledLogLevels(String JavaDoc logMode);
203
204     abstract public boolean setMessage(String JavaDoc key, String JavaDoc value);
205
206     abstract public String JavaDoc getMessage(String JavaDoc key);
207
208     abstract public boolean writeEcho (String JavaDoc strLogTxt);
209
210     abstract public void close();
211   }
212
213
Popular Tags