KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Level;
20
21
22 /**
23  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
24  */

25 public class Log4jLogger implements Logger {
26    private final org.apache.log4j.Logger logger;
27
28    public Log4jLogger(String JavaDoc pCName) {
29       logger = org.apache.log4j.Logger.getLogger(pCName);
30    }
31
32    protected String JavaDoc format(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
33       final StringBuffer JavaDoc sb = new StringBuffer JavaDoc(pMethodName);
34       sb.append(": ").append(pMsg);
35       if (pDetails != null) {
36          for (int i = 0; i < pDetails.length; i++) {
37             sb.append(", ");
38             sb.append(pDetails[i]);
39          }
40       }
41       return sb.toString();
42    }
43
44    protected String JavaDoc format(String JavaDoc pMethodName, Object JavaDoc[] pDetails) {
45       final StringBuffer JavaDoc sb = new StringBuffer JavaDoc(pMethodName);
46       if (pDetails != null) {
47          String JavaDoc add = ": ";
48          for (int i = 0; i < pDetails.length; i++) {
49             sb.append(add);
50             add = ", ";
51             sb.append(pDetails[i]);
52          }
53       }
54       return sb.toString();
55    }
56
57     public void entering(String JavaDoc pMethodName, Object JavaDoc[] pDetails) {
58       if (logger.isDebugEnabled()) {
59          logger.debug(format(pMethodName + " ->", pDetails));
60       }
61     }
62
63     public void entering(String JavaDoc pMethodName) {
64       if (logger.isDebugEnabled()) {
65          logger.debug(pMethodName + " ->");
66       }
67     }
68
69     public void entering(String JavaDoc pMethodName, Object JavaDoc pDetails) {
70       if (logger.isDebugEnabled()) {
71          logger.debug(pMethodName + " ->: " + pDetails);
72       }
73     }
74
75     public void exiting(String JavaDoc pMethodName, Object JavaDoc[] pDetails) {
76       if (logger.isDebugEnabled()) {
77          logger.debug(format(pMethodName + " <-", pDetails));
78       }
79     }
80
81     public void exiting(String JavaDoc pMethodName) {
82       if (logger.isDebugEnabled()) {
83          logger.debug(pMethodName + " <-");
84       }
85     }
86
87     public void exiting(String JavaDoc pMethodName, Object JavaDoc pDetails) {
88       if (logger.isDebugEnabled()) {
89          logger.debug(pMethodName + " <-: " + pDetails);
90       }
91     }
92
93     public void throwing(String JavaDoc pMethodName, Throwable JavaDoc pThrowable) {
94       logger.error(pMethodName, pThrowable);
95     }
96
97     public boolean isFinestEnabled() {
98       return logger.isDebugEnabled();
99     }
100
101     public void finest(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
102       if (logger.isDebugEnabled()) {
103          logger.debug(format(pMethodName, pMsg, pDetails));
104       }
105     }
106
107     public void finest(String JavaDoc pMethodName, String JavaDoc pMsg) {
108       if (logger.isDebugEnabled()) {
109          logger.debug(pMethodName + ": " + pMsg);
110       }
111     }
112
113     public void finest(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
114       if (logger.isDebugEnabled()) {
115          logger.debug(pMethodName + ": " + pMsg + ", " + pDetails);
116       }
117     }
118
119     public void finer(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
120       finest(pMethodName, pMsg, pDetails);
121     }
122
123     public boolean isFinerEnabled() {
124       return isFinestEnabled();
125     }
126
127     public void finer(String JavaDoc pMethodName, String JavaDoc pMsg) {
128       finest(pMethodName, pMsg);
129     }
130
131     public void finer(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
132       finest(pMethodName, pMsg, pDetails);
133     }
134
135     public boolean isFineEnabled() {
136       return isFinestEnabled();
137     }
138
139     public void fine(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
140       finest(pMethodName, pMsg, pDetails);
141     }
142
143     public void fine(String JavaDoc pMethodName, String JavaDoc pMsg) {
144       finest(pMethodName, pMsg);
145     }
146
147     public void fine(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
148       finest(pMethodName, pMsg, pDetails);
149     }
150
151     public boolean isInfoEnabled() {
152       return logger.isInfoEnabled();
153     }
154
155     public void info(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
156       if (logger.isInfoEnabled()) {
157          logger.info(format(pMethodName, pMsg, pDetails));
158       }
159     }
160
161     public void info(String JavaDoc pMethodName, String JavaDoc pMsg) {
162       if (logger.isInfoEnabled()) {
163          logger.info(pMethodName + ": " + pMsg);
164       }
165     }
166
167     public void info(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
168       if (logger.isInfoEnabled()) {
169          logger.info(pMethodName + ": " + pMsg + ", " + pDetails);
170       }
171     }
172
173     public boolean isWarnEnabled() {
174       return logger.isEnabledFor(Level.WARN);
175     }
176
177     public void warn(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
178       if (logger.isEnabledFor(Level.WARN)) {
179          logger.warn(format(pMethodName, pMsg, pDetails));
180       }
181     }
182
183     public void warn(String JavaDoc pMethodName, String JavaDoc pMsg) {
184       if (logger.isEnabledFor(Level.WARN)) {
185          logger.warn(pMethodName + ": " + pMsg);
186       }
187     }
188
189     public void warn(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
190       if (logger.isEnabledFor(Level.WARN)) {
191          logger.warn(pMethodName + ": " + pMsg + ", " + pDetails);
192       }
193     }
194
195     public boolean isErrorEnabled() {
196       return logger.isEnabledFor(Level.ERROR);
197     }
198
199     public void error(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
200       if (logger.isEnabledFor(Level.ERROR)) {
201          logger.error(format(pMethodName, pMsg, pDetails));
202       }
203     }
204
205     public void error(String JavaDoc pMethodName, String JavaDoc pMsg) {
206       if (logger.isEnabledFor(Level.ERROR)) {
207          logger.error(pMethodName + ": " + pMsg);
208       }
209     }
210
211     public void error(String JavaDoc pMethodName, String JavaDoc pMsg, Object JavaDoc pDetails) {
212       if (logger.isEnabledFor(Level.ERROR)) {
213          logger.error(pMethodName + ": " + pMsg + ", " + pDetails);
214       }
215     }
216 }
217
Popular Tags