KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > system > logging > Log4JLogger


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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
19 import org.apache.log4j.*;
20
21 import java.io.PrintWriter JavaDoc;
22 import java.io.StringWriter JavaDoc;
23
24
25 public class Log4JLogger implements Logger
26 {
27     private Category cat = Category.getInstance("jftp");
28
29     public Log4JLogger()
30     {
31         BasicConfigurator.configure();
32     }
33
34     private String JavaDoc stacktrace(Throwable JavaDoc throwable)
35     {
36         StringWriter JavaDoc out = new StringWriter JavaDoc();
37         throwable.printStackTrace(new PrintWriter JavaDoc(out));
38
39         return (throwable.toString());
40     }
41
42     public void debug(String JavaDoc msg)
43     {
44         cat.debug(msg);
45     }
46
47     public void debugRaw(String JavaDoc msg)
48     {
49         cat.debug(msg);
50     }
51
52     public void debug(String JavaDoc msg, Throwable JavaDoc throwable)
53     {
54         cat.debug(msg);
55         cat.debug(stacktrace(throwable));
56     }
57
58     public void warn(String JavaDoc msg)
59     {
60         cat.warn(msg);
61     }
62
63     public void warn(String JavaDoc msg, Throwable JavaDoc throwable)
64     {
65         cat.warn(msg);
66         cat.warn(stacktrace(throwable));
67     }
68
69     public void error(String JavaDoc msg)
70     {
71         cat.error(msg);
72     }
73
74     public void error(String JavaDoc msg, Throwable JavaDoc throwable)
75     {
76         cat.error(msg);
77         cat.error(stacktrace(throwable));
78     }
79
80     public void info(String JavaDoc msg)
81     {
82         cat.info(msg);
83     }
84
85     public void info(String JavaDoc msg, Throwable JavaDoc throwable)
86     {
87         cat.info(msg);
88         cat.info(stacktrace(throwable));
89     }
90
91     public void fatal(String JavaDoc msg)
92     {
93         cat.fatal(msg);
94     }
95
96     public void fatal(String JavaDoc msg, Throwable JavaDoc throwable)
97     {
98         cat.fatal(msg);
99         cat.fatal(stacktrace(throwable));
100     }
101 }
102
Popular Tags