KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > util > ComponentLogger


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: Logger.java 3:03:53 PM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common.util;
23
24 import java.util.Enumeration JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import java.util.logging.Filter JavaDoc;
27 import java.util.logging.Handler JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.LogRecord JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31
32 /**
33  * Logger for the component wraps a java logger
34  *
35  * @author ddesjardins - eBMWebsourcing
36  */

37 public class ComponentLogger extends Logger JavaDoc {
38
39     /**
40      * Component Name
41      */

42     protected String JavaDoc componentName;
43
44     /**
45      * Java logger
46      */

47     protected Logger JavaDoc logger;
48
49     public ComponentLogger(Logger JavaDoc logger, String JavaDoc loggerName,
50         String JavaDoc resourceBundleName, String JavaDoc componentName) {
51         super(loggerName, resourceBundleName);
52         this.logger = logger;
53         this.componentName = componentName;
54     }
55
56     public void addHandler(Handler JavaDoc handler) throws SecurityException JavaDoc {
57         logger.addHandler(handler);
58     }
59
60     public void config(String JavaDoc msg) {
61         logger.config(msg);
62     }
63
64     public void entering(String JavaDoc sourceClass, String JavaDoc sourceMethod) {
65         logger.entering(sourceClass, sourceMethod);
66     }
67
68     public void entering(String JavaDoc sourceClass, String JavaDoc sourceMethod, Object JavaDoc param1) {
69         logger.entering(sourceClass, sourceMethod, param1);
70     }
71
72     public void entering(String JavaDoc sourceClass, String JavaDoc sourceMethod,
73         Object JavaDoc[] params) {
74         logger.entering(sourceClass, sourceMethod, params);
75     }
76
77     public boolean equals(Object JavaDoc obj) {
78         return logger.equals(obj);
79     }
80
81     public void exiting(String JavaDoc sourceClass, String JavaDoc sourceMethod) {
82         logger.exiting(sourceClass, sourceMethod);
83     }
84
85     public void exiting(String JavaDoc sourceClass, String JavaDoc sourceMethod, Object JavaDoc result) {
86         logger.exiting(sourceClass, sourceMethod, result);
87     }
88
89     public void fine(String JavaDoc msg) {
90         logger.fine("["
91             + componentName + "] " + convertMsg(msg));
92     }
93
94     public void finer(String JavaDoc msg) {
95         logger.finer("["
96             + componentName + "] " + convertMsg(msg));
97     }
98
99     public void finest(String JavaDoc msg) {
100         logger.finest("["
101             + componentName + "] " + convertMsg(msg));
102     }
103
104     public Filter JavaDoc getFilter() {
105         return logger.getFilter();
106     }
107
108     public Handler JavaDoc[] getHandlers() {
109         return logger.getHandlers();
110     }
111
112     public Level JavaDoc getLevel() {
113         return logger.getLevel();
114     }
115
116     public String JavaDoc getName() {
117         return logger.getName();
118     }
119
120     public Logger JavaDoc getParent() {
121         return logger.getParent();
122     }
123
124     public ResourceBundle JavaDoc getResourceBundle() {
125         return logger.getResourceBundle();
126     }
127
128     public String JavaDoc getResourceBundleName() {
129         return logger.getResourceBundleName();
130     }
131
132     public boolean getUseParentHandlers() {
133         return logger.getUseParentHandlers();
134     }
135
136     public int hashCode() {
137         return logger.hashCode();
138     }
139
140     public void info(String JavaDoc msg) {
141         logger.info("["
142             + componentName + "] " + convertMsg(msg));
143     }
144
145     public boolean isLoggable(Level JavaDoc level) {
146         return logger.isLoggable(level);
147     }
148
149     public void log(Level JavaDoc level, String JavaDoc msg) {
150         logger.log(level, "["
151             + componentName + "] " + convertMsg(msg));
152     }
153
154     public void log(Level JavaDoc level, String JavaDoc msg, Object JavaDoc param1) {
155         logger.log(level, "["
156             + componentName + "] " + convertMsg(msg), param1);
157     }
158
159     public void log(Level JavaDoc level, String JavaDoc msg, Object JavaDoc[] params) {
160         logger.log(level, "["
161             + componentName + "] " + convertMsg(msg), params);
162     }
163
164     public void log(Level JavaDoc level, String JavaDoc msg, Throwable JavaDoc thrown) {
165         logger.log(level, "["
166             + componentName + "] " + convertMsg(msg), thrown);
167     }
168
169     public void log(LogRecord JavaDoc record) {
170         logger.log(record);
171     }
172
173     public void logp(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
174         String JavaDoc msg) {
175         logger.logp(level, sourceClass, sourceMethod, "["
176             + componentName + "] " + convertMsg(msg));
177     }
178
179     public void logp(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
180         String JavaDoc msg, Object JavaDoc param1) {
181         logger.logp(level, sourceClass, sourceMethod, "["
182             + componentName + "] " + convertMsg(msg), param1);
183     }
184
185     public void logp(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
186         String JavaDoc msg, Object JavaDoc[] params) {
187         logger.logp(level, sourceClass, sourceMethod, "["
188             + componentName + "] " + convertMsg(msg), params);
189     }
190
191     public void logp(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
192         String JavaDoc msg, Throwable JavaDoc thrown) {
193         logger.logp(level, sourceClass, sourceMethod, "["
194             + componentName + "] " + convertMsg(msg), thrown);
195     }
196
197     public void logrb(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
198         String JavaDoc bundleName, String JavaDoc msg) {
199         logger.logrb(level, sourceClass, sourceMethod, bundleName, "["
200             + componentName + "] " + convertMsg(msg));
201     }
202
203     public void logrb(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
204         String JavaDoc bundleName, String JavaDoc msg, Object JavaDoc param1) {
205         logger.logrb(level, sourceClass, sourceMethod, bundleName, "["
206             + componentName + "] " + convertMsg(msg), param1);
207     }
208
209     public void logrb(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
210         String JavaDoc bundleName, String JavaDoc msg, Object JavaDoc[] params) {
211         logger.logrb(level, sourceClass, sourceMethod, bundleName, "["
212             + componentName + "] " + convertMsg(msg), params);
213     }
214
215     public void logrb(Level JavaDoc level, String JavaDoc sourceClass, String JavaDoc sourceMethod,
216         String JavaDoc bundleName, String JavaDoc msg, Throwable JavaDoc thrown) {
217         logger.logrb(level, sourceClass, sourceMethod, bundleName, "["
218             + componentName + "] " + convertMsg(msg), thrown);
219     }
220
221     public void removeHandler(Handler JavaDoc handler) throws SecurityException JavaDoc {
222         logger.removeHandler(handler);
223     }
224
225     public void setFilter(Filter JavaDoc newFilter) throws SecurityException JavaDoc {
226         logger.setFilter(newFilter);
227     }
228
229     public void setLevel(Level JavaDoc newLevel) throws SecurityException JavaDoc {
230         logger.setLevel(newLevel);
231     }
232
233     public void setParent(Logger JavaDoc parent) {
234         logger.setParent(parent);
235     }
236
237     public void setUseParentHandlers(boolean useParentHandlers) {
238         logger.setUseParentHandlers(useParentHandlers);
239     }
240
241     public void severe(String JavaDoc msg) {
242         logger.severe("["
243             + componentName + "] " + convertMsg(msg));
244     }
245
246     public void throwing(String JavaDoc sourceClass, String JavaDoc sourceMethod,
247         Throwable JavaDoc thrown) {
248         logger.throwing(sourceClass, sourceMethod, thrown);
249     }
250
251     public String JavaDoc toString() {
252         return logger.toString();
253     }
254
255     public void warning(String JavaDoc msg) {
256         logger.warning("["
257             + componentName + "] " + convertMsg(msg));
258     }
259
260     protected String JavaDoc convertMsg(String JavaDoc msg) {
261         String JavaDoc out = msg;
262         if (logger.getResourceBundle() != null) {
263             Enumeration JavaDoc<String JavaDoc> enumeration = logger.getResourceBundle()
264                 .getKeys();
265             while (enumeration.hasMoreElements()) {
266                 String JavaDoc key = enumeration.nextElement();
267                 if (key.equals(msg)) {
268                     out = logger.getResourceBundle().getString(msg);
269                     break;
270                 }
271             }
272         }
273         return out;
274     }
275
276 }
277
Popular Tags