KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > logging > Logger


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Logger.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
22  */

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

73 public abstract class Logger {
74
75     /**
76      * Standard level for urgent condition that requires immediate attention
77      * and indicates that the system is no longer functioning.
78      */

79     public static final int EMERGENCY = 0;
80
81     /**
82      * A condition that should be corrected immediately
83      */

84     public static final int ALERT = 1;
85
86     /**
87      * Critical conditions.
88      */

89     public static final int CRITICAL = 2;
90
91     /**
92      * Errors that have been correctly handled.
93      */

94     public static final int ERROR = 3;
95
96     /**
97      * Warning messages.
98      */

99     public static final int WARNING = 4;
100
101     /**
102      * Conditions that are not error conditions, but should possi bly be
103      * handled specially.
104      */

105     public static final int NOTICE = 5;
106
107     /**
108      * Informational messages.
109      */

110     public static final int INFO = 6;
111
112     /**
113      * Messages that contain information normally of use only when debugging.
114      * This is the basic level of debugging. Levels DEBUG1 through DEBUG9
115      * are defined to allow for more detailed messages.
116      */

117     public static final int DEBUG = 7;
118
119     /**
120      * Debug detail level 1.
121      */

122     public static final int DEBUG1 = 8;
123
124     /**
125      * Debug detail level 2.
126      */

127     public static final int DEBUG2 = 9;
128
129     /**
130      * Debug detail level 3.
131      */

132     public static final int DEBUG3 = 10;
133
134     /**
135      * Debug detail level 4.
136      */

137     public static final int DEBUG4 = 11;
138
139     /**
140      * Debug detail level 5.
141      */

142     public static final int DEBUG5 = 12;
143
144     /**
145      * Debug detail level 6.
146      */

147     public static final int DEBUG6 = 13;
148
149     /**
150      * Debug detail level 7.
151      */

152     public static final int DEBUG7 = 14;
153
154     /**
155      * Debug detail level 8.
156      */

157     public static final int DEBUG8 = 15;
158
159     /**
160      * Debug detail level 9.
161      */

162     public static final int DEBUG9 = 16;
163
164     /**
165      * Temporary debugging; should not be left in shipping code.
166      */

167     public static final int DEBUGTMP = 17;
168
169     /**
170      * Largest fixed logging level.
171      */

172     public static final int MAX_STD_LEVEL = DEBUGTMP;
173
174     /**
175      * Global <CODE>Logger</CODE> object.
176      */

177     protected static Logger centralLogger;
178
179     /**
180      * Table of standard level names
181      */

182     protected static final String JavaDoc[] standardLevelNames = {
183         "EMERGENCY", // 0
184
"ALERT", // 1
185
"CRITICAL", // 2
186
"ERROR", // 3
187
"WARNING", // 4
188
"NOTICE", // 5
189
"INFO", // 6
190
"DEBUG", // 7
191
"DEBUG1", // 8
192
"DEBUG2", // 9
193
"DEBUG3", // 10
194
"DEBUG4", // 11
195
"DEBUG5", // 12
196
"DEBUG6", // 13
197
"DEBUG7", // 14
198
"DEBUG8", // 15
199
"DEBUG9", // 16
200
"DEBUGTMP" // 17
201
};
202
203     /**
204      * Get the central (global) logging object.
205      *
206      * @return A reference the object. If the facility has not been
207      * initialized <CODE>null</CODE> is returned. However, this is
208      * considered a bug in the design of the initialization. Clients
209      * do not need to check for <CODE>null</CODE>.
210      */

211     public static Logger getCentralLogger() {
212         return centralLogger;
213     }
214
215     /**
216      * Get the log channel object for a facility. For a given facility,
217      * the same object is always returned.
218      *
219      * @param facility Facility the channel is associated with.
220      */

221     abstract public LogChannel getChannel(String JavaDoc facility);
222
223     /**
224      * Configure Logger with given config file, interpreting of config file is
225      * logger implementation specific.
226      *
227      * @param confFilePath Path to configuration file.
228      */

229     abstract public void configure(String JavaDoc confFilePath) throws ConfigException;
230
231     /**
232      * Configure Logger with given config section
233      *
234      * @param logConfig containing parameters for configuring logger
235      */

236     abstract public void configure(Config logConfig) throws ConfigException;
237 }
238
Popular Tags