01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.system.logging;
17:
18: import org.apache.log4j.*;
19:
20: import java.io.PrintWriter;
21: import java.io.StringWriter;
22:
23: public class Log4JLogger implements Logger {
24: private Category cat = Category.getInstance("jftp");
25:
26: public Log4JLogger() {
27: BasicConfigurator.configure();
28: }
29:
30: private String stacktrace(Throwable throwable) {
31: StringWriter out = new StringWriter();
32: throwable.printStackTrace(new PrintWriter(out));
33:
34: return (throwable.toString());
35: }
36:
37: public void debug(String msg) {
38: cat.debug(msg);
39: }
40:
41: public void debugRaw(String msg) {
42: cat.debug(msg);
43: }
44:
45: public void debug(String msg, Throwable throwable) {
46: cat.debug(msg);
47: cat.debug(stacktrace(throwable));
48: }
49:
50: public void warn(String msg) {
51: cat.warn(msg);
52: }
53:
54: public void warn(String msg, Throwable throwable) {
55: cat.warn(msg);
56: cat.warn(stacktrace(throwable));
57: }
58:
59: public void error(String msg) {
60: cat.error(msg);
61: }
62:
63: public void error(String msg, Throwable throwable) {
64: cat.error(msg);
65: cat.error(stacktrace(throwable));
66: }
67:
68: public void info(String msg) {
69: cat.info(msg);
70: }
71:
72: public void info(String msg, Throwable throwable) {
73: cat.info(msg);
74: cat.info(stacktrace(throwable));
75: }
76:
77: public void fatal(String msg) {
78: cat.fatal(msg);
79: }
80:
81: public void fatal(String msg, Throwable throwable) {
82: cat.fatal(msg);
83: cat.fatal(stacktrace(throwable));
84: }
85: }
|