KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > logger > Logger


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ioc.logger;
7
8 import org.apache.log4j.Level;
9
10 /**
11  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
12  */

13
14 public class Logger {
15
16     private org.apache.log4j.Logger logger;
17
18     static {
19         _init();
20     }
21
22     /**
23      * set rootLogger
24      */

25     private static void _init() {
26         LoggerMananger.class.getName();
27     }
28
29     public static Logger getLogger(String JavaDoc name) {
30         return new Logger(name);
31     }
32
33     public static Logger getLogger(Class JavaDoc clz) {
34         return new Logger(clz.getName());
35     }
36
37     private Logger(String JavaDoc name) {
38         logger = org.apache.log4j.Logger.getLogger(name);
39     }
40
41     /**
42      * <p> Log a message with debug log level. </p>
43      *
44      * @param message log this message
45      */

46     public void trace(Object JavaDoc message) {
47         logger.log(Level.DEBUG, message);
48     }
49
50
51     /**
52      * <p> Log an error with debug log level. </p>
53      *
54      * @param message log this message
55      * @param t log this cause
56      */

57     public void trace(Object JavaDoc message, Throwable JavaDoc t) {
58         logger.log(Level.DEBUG, message, t);
59     }
60
61     /**
62      * <p> Log a message with debug log level. </p>
63      *
64      * @param message log this message
65      */

66     public void debug(Object JavaDoc message) {
67         logger.log(Level.DEBUG, message);
68     }
69
70
71     /**
72      * <p> Log an error with debug log level. </p>
73      *
74      * @param message log this message
75      * @param t log this cause
76      */

77     public void debug(Object JavaDoc message, Throwable JavaDoc t) {
78         logger.log(Level.DEBUG, message, t);
79     }
80
81
82     /**
83      * <p> Log a message with info log level. </p>
84      *
85      * @param message log this message
86      */

87     public void info(Object JavaDoc message) {
88         logger.log(Level.INFO, message);
89     }
90
91
92     /**
93      * <p> Log an error with info log level. </p>
94      *
95      * @param message log this message
96      * @param t log this cause
97      */

98     public void info(Object JavaDoc message, Throwable JavaDoc t) {
99         logger.log(Level.INFO, message, t);
100     }
101
102
103     /**
104      * <p> Log a message with warn log level. </p>
105      *
106      * @param message log this message
107      */

108     public void warn(Object JavaDoc message) {
109         logger.log(Level.WARN, message);
110     }
111
112
113     /**
114      * <p> Log an error with warn log level. </p>
115      *
116      * @param message log this message
117      * @param t log this cause
118      */

119     public void warn(Object JavaDoc message, Throwable JavaDoc t) {
120         logger.log(Level.WARN, message, t);
121     }
122
123
124     /**
125      * <p> Log a message with error log level. </p>
126      *
127      * @param message log this message
128      */

129     public void error(Object JavaDoc message) {
130         logger.log(Level.ERROR, message);
131     }
132
133
134     /**
135      * <p> Log an error with error log level. </p>
136      *
137      * @param message log this message
138      * @param t log this cause
139      */

140     public void error(Object JavaDoc message, Throwable JavaDoc t) {
141         logger.log(Level.ERROR, message, t);
142     }
143
144
145     /**
146      * <p> Log a message with fatal log level. </p>
147      *
148      * @param message log this message
149      */

150     public void fatal(Object JavaDoc message) {
151         logger.log(Level.FATAL, message);
152     }
153
154
155     /**
156      * <p> Log an error with fatal log level. </p>
157      *
158      * @param message log this message
159      * @param t log this cause
160      */

161     public void fatal(Object JavaDoc message, Throwable JavaDoc t) {
162         logger.log(Level.FATAL, message, t);
163     }
164
165     public boolean isTraceEnabled() {
166         return true;
167     }
168
169     public boolean isDebugEnabled() {
170         return logger.isDebugEnabled();
171     }
172
173     public boolean isInfoEnabled() {
174         return logger.isInfoEnabled();
175     }
176
177     public boolean isWarnEnabled() {
178         return logger.isEnabledFor(Level.WARN);
179
180     }
181
182     public boolean isErrorEnabled() {
183         return logger.isEnabledFor(Level.ERROR);
184     }
185
186     public boolean isFatalEnabled() {
187         return logger.isEnabledFor(Level.FATAL);
188     }
189
190     public static void main(String JavaDoc[] args) {
191         Logger logger = Logger.getLogger("test");
192         logger.info("test message");
193
194     }
195 }
196
197
Popular Tags