KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > logging > Logger


1 /*
2 This software is OSI Certified Open Source Software.
3 OSI Certified is a certification mark of the Open Source Initiative.
4
5 The license (Mozilla version 1.0) can be read at the MMBase site.
6 See http://www.MMBase.org/license
7
8 */

9
10 package org.mmbase.util.logging;
11
12 /**
13  * The `Logger' interface for MMBase.
14  *
15  * It was designed for use with Log4j, but it is of course easy to
16  * implement it differently as well.
17  * <p>
18  * Implementations should also supply a getLoggerInstance static
19  * method, and can supply a configure static method.
20  * </p>
21  * </p>
22  * For example:
23  * <code>
24  * <pre>
25  * <tt>
26  * <b><font color=#0000FF>import</font></b> org.mmbase.util.logging.Logging;
27  * <b><font color=#0000FF>import</font></b> org.mmbase.util.logging.Logger;
28  *
29  * <b><font color=#0000FF>public</font></b> <b><font color=#0000FF>class</font></b> Foo {
30  * <b><font color=#0000FF>static</font></b> Logger log = Logging.getLoggerInstance(Foo.<b><font color=#0000FF>class</font></b>.getName());
31  * <b><font color=#0000FF>public</font></b> <font color=#009900>void</font> bar() {
32  * ...
33  * log.info(<font color=#FF0000>"Hello world!"</font>);
34  * ...
35  * <b><font color=#0000FF>if</font></b>(log.isDebugEnabled()) {
36  * log.debug(<font color=#FF0000>"Oops, that's not quite right!"</font>);
37  * }
38  * ...
39  * }
40  * }
41  * </tt>
42  * </pre>
43  * </code>
44  * </p>
45  *
46  * @author Michiel Meeuwissen
47  *
48  **/

49
50 public interface Logger {
51
52     // these static methods should also be implemented:
53
// public static void configure(String s); // well, this one is optional
54
// public static Logger getLoggerInstance(String name);
55

56     /**
57      * Logs the message m with trace priority. For detailled debugging.
58      * @see #debug(Object)
59      */

60     void trace(Object JavaDoc m);
61
62     /**
63      * @since MMBase-1.8
64      */

65
66     void trace(Object JavaDoc m, Throwable JavaDoc t);
67
68     /**
69      * Logs the message m with debug priority. Everything a
70      * non-developer never wants to see, but you do, to * keep track
71      * of what is happening. There can be a lot of them in the code,
72      * so it is important that you well protect them with
73      * `isDebugEnabled's, to minimize overhead.
74      */

75     void debug(Object JavaDoc m);
76
77     /**
78      * @since MMBase-1.8
79      */

80
81     void debug(Object JavaDoc m, Throwable JavaDoc t);
82
83
84     /**
85      * Logs the message m with service priority. An interested system
86      * administrator might want to see these things. For examples all
87      * queries to the database could be logged with `service'
88      * priority. Or if a image is calculated, that could be logged as
89      * a `service'. One would get a fairly good idea what MMBase is
90      * doing if `service' is switched on.
91      */

92     void service(Object JavaDoc m);
93
94     /**
95      * @since MMBase-1.8
96      */

97
98     void service(Object JavaDoc m, Throwable JavaDoc t);
99
100
101     /**
102      * Logs the message m with info priority. As `service', but
103      * focussed on things system administrators are usually most
104      * interested in, like authorisation issues. For example changes on
105      * the database could be logged, such that one can see in the logs
106      * what happened.
107      */

108     void info(Object JavaDoc m);
109
110     /**
111      * @since MMBase-1.8
112      */

113     void info(Object JavaDoc m, Throwable JavaDoc t);
114
115
116     /**
117      * Logs the message m with warn priority. Something strange
118      * happened, but it is not necessarily an error.
119      */

120     void warn(Object JavaDoc m);
121
122     /**
123      * @since MMBase-1.8
124      */

125     void warn(Object JavaDoc m, Throwable JavaDoc t);
126
127
128     /**
129      * Logs the message m with error priority. Something is definitely
130      * wrong. An inconsistency was detected. It might be unpredictable
131      * what will happen.
132      */

133     void error(Object JavaDoc m);
134
135     /**
136      * @since MMBase-1.8
137      */

138     void error(Object JavaDoc m, Throwable JavaDoc t);
139
140
141     /**
142      * Logs the message m with fatal priority. The progam could not
143      * function any more. Normally, you would throw an exception,
144      * which then will be logged with fatal priority. I've made an
145      * arangement in `Logger' that logs uncatched exceptions with
146      * fatal priority, but nevertheless it's better to always catch
147      * all exceptions in a more regulated way.
148      */

149     void fatal(Object JavaDoc m);
150
151     /**
152      * @since MMBase-1.8
153      */

154     void fatal(Object JavaDoc m, Throwable JavaDoc t);
155
156     /**
157      * Returns true if for this category (Logger), a call to trace
158      * would do something.
159      */

160     public boolean isTraceEnabled();
161
162
163     /**
164      * Returns true if for this category (Logger), a call to debug (or
165      * trace) would do something.
166      */

167     public boolean isDebugEnabled();
168     // public boolean isInfoEnabled();
169

170     /**
171      * Returns true if for this category (Logger), a call to service
172      * (or debug or trace) would do something.
173      */

174     public boolean isServiceEnabled();
175
176
177     /**
178      * If you want to override the level in the configuration file
179      * fixed for this category, you can do it with this method. This
180      * could be usefull for example to switch on all debug logging
181      * when something has gone wrong.
182      * @param p The level of the priority. One of the constants
183      * Level.TRACE, Level.DEBUG, Level.SERVICE, Level.INFO,
184      * Level.WARN, Level.ERROR or Level.FATAL.
185      */

186
187     public void setLevel(Level p);
188
189 }
190
Popular Tags