001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: Logger.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
022: */
023: package com.lutris.logging;
024:
025: import com.lutris.util.Config;
026: import com.lutris.util.ConfigException;
027:
028: /**
029: * A general-purpose logging facility. It is modeled after
030: * <CODE>syslogd</CODE>. This is a base class from which an actual
031: * implementation is derived. It only defines how log message are written
032: * by a client. Where the log message is written and the mechanism for
033: * controlling logging is left up to the implementation. This class does
034: * not define any of these mechanism and their definition is not necessary
035: * for understand how to use this class. <P>
036: *
037: * Each log message is associate with a facility and has a level assigned
038: * to it. A facility is a symbolic (String) name that defines a class of
039: * log messages. A level is used to indicate the
040: *
041: It is expected that the implementation can enable, disable and
042: * direct log messages based on these attributes. Facilities and levels
043: * are defined symbolicly, with no restriction on the name, and form a tuple.
044: * Several standard levels are defined as integer constants and their use
045: * is expected to be higher performing than symbolic levels..<P>
046: *
047: *
048: *Normally, a single,
049: global instance of the object
050: * is exists and is obtainable by a static method in this class.<P>
051: *
052: * Log messages are written via an object implementing <CODE>LogChannel</CODE>.
053: * A channel is associated with a single facility, with the level being
054: * specified when a message is written. Normally, a <CODE>LogChannel</CODE>
055: * is obtained once at initialization time and use repeatedly. It is
056: * permissible to obtain multiple references to the log channel for a facility,
057: * but this is discouraged for performance reasons.<P>
058: *
059: * Log messages, even debugging ones, should be defined with care. They
060: * should be terse, but clear to someone who isn't intimately familiar with
061: * the code. Permanent debugging messages should be designed with the idea
062: * of use when supportting a deployed product.<P>
063: *
064: * The central logging object needs to be configured very early in the startup
065: * process. If logging can't be configured, then the startup should be aborted
066: * or a object created that does some simple form of logging, such as write
067: * to <CODE>stderr<CODE>. A client should never have to check if the global
068: * logger object exists.<P>
069: *
070: * @author Mark Diekhans
071: * @see com.lutris.logging.LogChannel
072: */
073: public abstract class Logger {
074:
075: /**
076: * Standard level for urgent condition that requires immediate attention
077: * and indicates that the system is no longer functioning.
078: */
079: public static final int EMERGENCY = 0;
080:
081: /**
082: * A condition that should be corrected immediately
083: */
084: public static final int ALERT = 1;
085:
086: /**
087: * Critical conditions.
088: */
089: public static final int CRITICAL = 2;
090:
091: /**
092: * Errors that have been correctly handled.
093: */
094: public static final int ERROR = 3;
095:
096: /**
097: * Warning messages.
098: */
099: 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[] standardLevelNames = { "EMERGENCY", // 0
183: "ALERT", // 1
184: "CRITICAL", // 2
185: "ERROR", // 3
186: "WARNING", // 4
187: "NOTICE", // 5
188: "INFO", // 6
189: "DEBUG", // 7
190: "DEBUG1", // 8
191: "DEBUG2", // 9
192: "DEBUG3", // 10
193: "DEBUG4", // 11
194: "DEBUG5", // 12
195: "DEBUG6", // 13
196: "DEBUG7", // 14
197: "DEBUG8", // 15
198: "DEBUG9", // 16
199: "DEBUGTMP" // 17
200: };
201:
202: /**
203: * Get the central (global) logging object.
204: *
205: * @return A reference the object. If the facility has not been
206: * initialized <CODE>null</CODE> is returned. However, this is
207: * considered a bug in the design of the initialization. Clients
208: * do not need to check for <CODE>null</CODE>.
209: */
210: public static Logger getCentralLogger() {
211: return centralLogger;
212: }
213:
214: /**
215: * Get the log channel object for a facility. For a given facility,
216: * the same object is always returned.
217: *
218: * @param facility Facility the channel is associated with.
219: */
220: abstract public LogChannel getChannel(String facility);
221:
222: /**
223: * Configure Logger with given config file, interpreting of config file is
224: * logger implementation specific.
225: *
226: * @param confFilePath Path to configuration file.
227: */
228: abstract public void configure(String confFilePath)
229: 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)
237: throws ConfigException;
238: }
|