1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.tools;
20
21 import org.apache.log4j.Level;
22 import org.apache.log4j.Logger;
23
24 /***
25 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
26 * @since 0.93
27 */
28 public final class Log {
29
30 private static Logger log = null;
31
32 private Log() {
33 super();
34 }
35
36 /***
37 * @param message
38 */
39 public static void fatal(String message) {
40 if (log == null) {
41 System.out.println("FATAL : "+message);
42 } else {
43 log.fatal(message);
44 }
45 throw new RuntimeException(message);
46 }
47
48 /***
49 * @param t
50 */
51 public static void fatal(Throwable t) {
52 if (log == null) {
53 System.out.println(t);
54 } else {
55 log.fatal(t);
56 }
57 throw new RuntimeException(t);
58 }
59
60 /***
61 * @param stack
62 */
63 public static void fatal(StackTraceElement[] stack) {
64 if (log == null) {
65 System.out.println(stack);
66 } else {
67 log.fatal(stack);
68 }
69 throw new RuntimeException("StackTraceElement[] stack");
70 }
71
72 /***
73 * @param message
74 * @param t
75 */
76 public static void fatal(String message, Throwable t) {
77 if (log == null) {
78 System.out.println("FATAL : "+message);
79 } else {
80 log.fatal(message, t);
81 }
82 throw new RuntimeException(message, t);
83 }
84
85 /***
86 * @param message
87 */
88 public static void debug(String message) {
89 if (log == null) {
90 System.out.println(message);
91 } else {
92 log.debug(message);
93 }
94 }
95
96 /***
97 * @param object
98 */
99 public static void debug(Object object) {
100 if (log == null) {
101 System.out.println(object);
102 } else {
103 log.debug(object);
104 }
105 }
106
107 /***
108 * @param t
109 */
110 public static void debug(Throwable t) {
111 if (log == null) {
112 System.out.println(t);
113 } else {
114 log.debug(t);
115 }
116 }
117
118 /***
119 * @param stack
120 */
121 public static void debug(StackTraceElement[] stack) {
122 if (log == null) {
123 System.out.println(stack);
124 } else {
125 log.debug(stack);
126 }
127 }
128
129 /***
130 * @param message
131 * @param t
132 */
133 public static void debug(String message, Throwable t) {
134 if (log == null) {
135 System.out.println(message);
136 } else {
137 log.debug(message, t);
138 }
139 }
140
141 /***
142 * @param message
143 */
144 public static void warn(String message) {
145 if (log == null) {
146 System.out.println("WARNING : "+message);
147 } else {
148 log.warn(message);
149 }
150 }
151
152 /***
153 * @param t
154 */
155 public static void warn(Throwable t) {
156 if (log == null) {
157 System.out.println(t);
158 } else {
159 log.warn(t);
160 }
161 }
162
163 /***
164 * @param stack
165 */
166 public static void warn(StackTraceElement[] stack) {
167 if (log == null) {
168 System.out.println("WARNING : "+stack);
169 } else {
170 log.warn(stack);
171 }
172 }
173
174 /***
175 * @param message
176 * @param t
177 */
178 public static void warn(String message, Throwable t) {
179 if (log == null) {
180 System.out.println("WARNING : "+message);
181 } else {
182 log.info(message, t);
183 }
184 }
185
186 /***
187 * @param message
188 */
189 public static void error(String message) {
190 if (log == null) {
191 System.err.println("ERROR : "+message);
192 } else {
193 log.error(message);
194 }
195 }
196
197 /***
198 * @param t
199 */
200 public static void error(Throwable t) {
201 if (log == null) {
202 System.out.println(t);
203 } else {
204 log.error(t);
205 }
206 }
207
208 /***
209 * @param stack
210 */
211 public static void error(StackTraceElement[] stack) {
212 if (log == null) {
213 System.out.println("ERROR : "+stack);
214 } else {
215 log.error(stack);
216 }
217 }
218
219 /***
220 * @param message
221 * @param t
222 */
223 public static void error(String message, Throwable t) {
224 if (log == null) {
225 System.out.println("ERROR : "+message);
226 } else {
227 log.error(message, t);
228 }
229
230 }
231
232 /***
233 * @param message
234 */
235 public static void info(String message) {
236 if (log == null) {
237 System.out.println(message);
238 } else {
239 log.info(message);
240 }
241 }
242
243 /***
244 * @param t
245 */
246 public static void info(Throwable t) {
247 if (log == null) {
248 System.out.println(t);
249 } else {
250 log.info(t);
251 }
252 }
253
254 /***
255 * @param stack
256 */
257 public static void info(StackTraceElement[] stack) {
258 if (log == null) {
259 System.out.println(stack);
260 } else {
261 log.info(stack);
262 }
263 }
264
265 /***
266 * @param message
267 * @param t
268 */
269 public static void info(String message, Throwable t) {
270 if (log == null) {
271 System.out.println(message);
272 } else {
273 log.info(message, t);
274 }
275 }
276
277 /***
278 *
279 */
280 public static void init() {
281 log = Logger.getRootLogger();
282 log.setLevel(Level.toLevel(Configuration.getString("logLevel", "DEBUG")));
283 }
284 }