KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > logging > LoggerImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.logging;
18
19 import java.io.PrintWriter JavaDoc;
20 import java.io.StringWriter JavaDoc;
21 import java.util.Date JavaDoc;
22
23
24 /** <p>Base implementation of a Logger.</p>
25  *
26  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
27  */

28 public class LoggerImpl implements Logger {
29    private final String JavaDoc cName;
30    private boolean loggingTime, loggingThread;
31
32    public LoggerImpl(String JavaDoc pCName) {
33       cName = pCName;
34    }
35
36    public boolean isLoggingTime() {
37       return loggingTime;
38    }
39
40    public boolean isLoggingThread() {
41       return loggingThread;
42    }
43
44    public void setLoggingTime(boolean pLoggingTime) {
45       loggingTime = pLoggingTime;
46    }
47
48    public void setLoggingThread(boolean pLoggingThread) {
49       loggingThread = pLoggingThread;
50    }
51
52    protected void log(String JavaDoc pMsg) {
53       System.err.println(pMsg);
54    }
55
56    protected void log(String JavaDoc pLevel, String JavaDoc pCName, String JavaDoc pMName, String JavaDoc pMsg) {
57       log(pLevel, pCName, pMName, new Object JavaDoc[]{pMsg});
58    }
59
60    protected void log(String JavaDoc pLevel, String JavaDoc pCName, String JavaDoc pMName,
61                        String JavaDoc pMsg, Object JavaDoc[] pDetails) {
62       if (pDetails == null) {
63          log(pLevel, pCName, pMName, new Object JavaDoc[]{pMsg});
64       } else {
65          Object JavaDoc[] o = new Object JavaDoc[pDetails.length+1];
66          o[0] = pMsg;
67          for (int i = 0; i < pDetails.length; i++) {
68             o[i+1] = pDetails[i];
69          }
70          log(pLevel, pCName, pMName, o);
71       }
72    }
73
74    protected void log(String JavaDoc pLevel, String JavaDoc pCName, String JavaDoc pMName,
75                        Object JavaDoc[] pDetails) {
76       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
77       if (loggingTime) {
78          sb.append(new Date JavaDoc());
79          sb.append(", ");
80       }
81       if (loggingThread) {
82          sb.append(Thread.currentThread().getName());
83          sb.append(", ");
84       }
85       sb.append(": ");
86       sb.append(pLevel).append(", ").append(pMName).append(", ");
87       if (pDetails != null) {
88          for (int i = 0; i < pDetails.length; i++) {
89             sb.append(", ").append(pDetails[i]);
90          }
91       }
92       log(sb.toString());
93    }
94
95    public boolean isFinestEnabled() { return true; }
96    public boolean isFinerEnabled() { return true; }
97    public boolean isFineEnabled() { return true; }
98    public boolean isInfoEnabled() { return true; }
99    public boolean isWarnEnabled() { return true; }
100    public boolean isErrorEnabled() { return true; }
101
102    public void finest(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
103       log("FINEST", cName, mName, pMsg, pDetails);
104    }
105
106    public void finest(String JavaDoc mName, String JavaDoc pMsg) {
107       log("FINEST", cName, mName, pMsg);
108    }
109
110    public void finest(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
111       log("FINEST", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
112    }
113
114    public void finer(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
115       log("FINER", cName, mName, pMsg, pDetails);
116    }
117
118    public void finer(String JavaDoc mName, String JavaDoc pMsg) {
119       log("FINER", cName, mName, pMsg);
120    }
121
122    public void finer(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
123       log("FINER", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
124    }
125
126    public void fine(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
127       log("FINE", cName, mName, pMsg, pDetails);
128    }
129
130    public void fine(String JavaDoc mName, String JavaDoc pMsg) {
131       log("FINE", cName, mName, pMsg);
132    }
133
134    public void fine(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
135       log("FINE", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
136    }
137
138    public void info(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
139       log("INFO", cName, mName, pMsg, pDetails);
140    }
141
142    public void info(String JavaDoc mName, String JavaDoc pMsg) {
143       log("INFO", cName, mName, pMsg);
144    }
145
146    public void info(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
147       log("INFO", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
148    }
149
150    public void warn(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
151       log("WARN", cName, mName, pMsg, pDetails);
152    }
153
154    public void warn(String JavaDoc mName, String JavaDoc pMsg) {
155       log("WARN", cName, mName, pMsg);
156    }
157
158    public void warn(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
159       log("WARN", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
160    }
161
162    public void error(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
163       log("ERROR", cName, mName, pMsg, pDetails);
164    }
165
166    public void error(String JavaDoc mName, String JavaDoc pMsg) {
167       log("ERROR", cName, mName, pMsg);
168    }
169
170    public void error(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
171       log("ERROR", cName, mName, new Object JavaDoc[]{pMsg, pDetails});
172    }
173
174     public void entering(String JavaDoc mName, Object JavaDoc[] pDetails) {
175       log("->", cName, mName, pDetails);
176     }
177
178     public void entering(String JavaDoc mName) {
179       log("->", cName, mName, (Object JavaDoc[]) null);
180     }
181
182     public void entering(String JavaDoc mName, Object JavaDoc pDetails) {
183       log("->", cName, mName, new Object JavaDoc[]{pDetails});
184     }
185
186     public void exiting(String JavaDoc mName, Object JavaDoc[] pDetails) {
187       log("<-", cName, mName, pDetails);
188     }
189
190     public void exiting(String JavaDoc mName) {
191       log("<-", cName, mName, (Object JavaDoc[]) null);
192     }
193
194     public void exiting(String JavaDoc mName, Object JavaDoc pDetails) {
195       log("<-", cName, mName, new Object JavaDoc[]{pDetails});
196     }
197
198     public void throwing(String JavaDoc mName, Throwable JavaDoc pThrowable) {
199       StringWriter JavaDoc sw = new StringWriter JavaDoc();
200       pThrowable.printStackTrace(new PrintWriter JavaDoc(sw));
201       log("THROWABLE", cName, mName, sw.toString());
202     }
203 }
204
Popular Tags