KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > wsrp > logging > WSRPLogger


1 /*
2  * Copyright 2005 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 package org.apache.cocoon.portal.wsrp.logging;
17
18 import org.apache.wsrp4j.log.Logger;
19
20 /**
21  * A wrapper for the cocoon logger<br/>
22  *
23  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
24  * @author <a HREF="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
25  *
26  * @version $Id: WSRPLogger.java 264755 2005-08-30 10:29:21Z cziegeler $
27  */

28 public class WSRPLogger implements Logger {
29
30     /** The avalon logger */
31     protected final org.apache.avalon.framework.logger.Logger logger;
32
33     /**
34      * constructor<br/>
35      *
36      * @param logger
37      */

38     public WSRPLogger(org.apache.avalon.framework.logger.Logger logger) {
39         this.logger = logger;
40     }
41
42     /**
43      * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String)
44      */

45     public void entry(int logLevel, String JavaDoc loggingMethod) {
46         this.entry(logLevel, loggingMethod, null);
47     }
48
49     /**
50      * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String, java.lang.Object)
51      */

52     public void entry(int logLevel, String JavaDoc loggingMethod, Object JavaDoc parm1) {
53         this.entry(logLevel, loggingMethod, new Object JavaDoc[] { parm1 });
54     }
55
56     /**
57      * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String, java.lang.Object[])
58      */

59     public void entry(int logLevel, String JavaDoc loggingMethod, Object JavaDoc[] parms) {
60         this.text(logLevel, loggingMethod, "Entering method", parms);
61     }
62
63     /**
64      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String)
65      */

66     public void exit(int logLevel, String JavaDoc loggingMethod) {
67         this.text(logLevel, loggingMethod, "Exiting method.");
68     }
69
70     /**
71      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, byte)
72      */

73     public void exit(int logLevel, String JavaDoc loggingMethod, byte retValue) {
74         this.exit(logLevel, loggingMethod, new Byte JavaDoc(retValue));
75     }
76
77     /**
78      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, short)
79      */

80     public void exit(int logLevel, String JavaDoc loggingMethod, short retValue) {
81         this.exit(logLevel, loggingMethod, new Short JavaDoc(retValue));
82     }
83
84     /**
85      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, int)
86      */

87     public void exit(int logLevel, String JavaDoc loggingMethod, int retValue) {
88         this.exit(logLevel, loggingMethod, new Integer JavaDoc(retValue));
89     }
90
91     /**
92      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, long)
93      */

94     public void exit(int logLevel, String JavaDoc loggingMethod, long retValue) {
95         this.exit(logLevel, loggingMethod, new Long JavaDoc(retValue));
96     }
97
98     /**
99      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, float)
100      */

101     public void exit(int logLevel, String JavaDoc loggingMethod, float retValue) {
102         this.exit(logLevel, loggingMethod, new Float JavaDoc(retValue));
103     }
104
105     /**
106      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, double)
107      */

108     public void exit(int logLevel, String JavaDoc loggingMethod, double retValue) {
109         this.exit(logLevel, loggingMethod, new Double JavaDoc(retValue));
110     }
111
112     /**
113      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, char)
114      */

115     public void exit(int logLevel, String JavaDoc loggingMethod, char retValue) {
116         this.exit(logLevel, loggingMethod, new Character JavaDoc(retValue));
117     }
118
119     /**
120      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, boolean)
121      */

122     public void exit(int logLevel, String JavaDoc loggingMethod, boolean retValue) {
123         this.exit(logLevel, loggingMethod, new Boolean JavaDoc(retValue));
124     }
125
126     /**
127      * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, java.lang.Object)
128      */

129     public void exit(int logLevel, String JavaDoc loggingMethod, Object JavaDoc retValue) {
130         this.text(logLevel, loggingMethod, "Exiting method. Returned value: {0}", retValue);
131     }
132
133     /**
134      * @see org.apache.wsrp4j.log.Logger#isLogging(int)
135      */

136     public boolean isLogging(int logLevel) {
137         if (logLevel == Logger.ERROR ) {
138             return this.logger.isErrorEnabled();
139         } else if ( logLevel == Logger.INFO ) {
140             return this.logger.isInfoEnabled();
141         } else if ( logLevel == Logger.WARN ) {
142             return this.logger.isWarnEnabled();
143         } else if ( logLevel == Logger.TRACE_HIGH ) {
144             return this.logger.isInfoEnabled();
145         } else if ( logLevel == Logger.TRACE_MEDIUM ) {
146             return this.logger.isDebugEnabled();
147         } else if ( logLevel == Logger.TRACE_LOW ) {
148             return this.logger.isDebugEnabled();
149         }
150         return false;
151     }
152
153     /**
154      * @see org.apache.wsrp4j.log.Logger#stackTrace(int, java.lang.String, java.lang.String)
155      */

156     public void stackTrace(int logLevel, String JavaDoc loggingMethod, String JavaDoc text) {
157         this.text(logLevel, loggingMethod, new Throwable JavaDoc("Stacktrace"), text);
158     }
159
160     /**
161      * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String)
162      */

163     public void text(int logLevel, String JavaDoc loggingMethod, String JavaDoc text) {
164         this.text(logLevel, loggingMethod, text, null);
165     }
166
167     /**
168      * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String, java.lang.Object)
169      */

170     public void text(int logLevel, String JavaDoc loggingMethod, String JavaDoc text, Object JavaDoc parm1) {
171         this.text(logLevel, loggingMethod, text, new Object JavaDoc[] { parm1 });
172     }
173
174     /**
175      * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String, java.lang.Object[])
176      */

177     public void text(int logLevel, String JavaDoc loggingMethod, String JavaDoc text, Object JavaDoc[] parms) {
178         this.text(logLevel, loggingMethod, (Throwable JavaDoc) null, text, parms);
179     }
180
181     /**
182      * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.Throwable, java.lang.String)
183      */

184     public void text(int logLevel, String JavaDoc loggingMethod, Throwable JavaDoc t, String JavaDoc text) {
185         this.text(logLevel, loggingMethod, t, text, null);
186     }
187
188     /**
189      * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.Throwable, java.lang.String, java.lang.Object[])
190      */

191     public void text(int logLevel, String JavaDoc loggingMethod, Throwable JavaDoc t, String JavaDoc text, Object JavaDoc[] parms) {
192         if (!this.isLogging(logLevel)) {
193             return;
194         }
195         StringBuffer JavaDoc msgBuffer = new StringBuffer JavaDoc();
196         if (loggingMethod != null) {
197             msgBuffer.append(loggingMethod);
198             msgBuffer.append(" - ");
199         }
200         if (text != null) {
201             msgBuffer.append(text);
202         }
203         if (parms != null) {
204             msgBuffer.append("\nParameters:\n");
205             for (int i = 0; i < parms.length; i++) {
206                 msgBuffer.append(parms[i]);
207             }
208         }
209
210         if (logLevel == Logger.ERROR ) {
211             this.logger.error(msgBuffer.toString(), t);
212         } else if ( logLevel == Logger.INFO ) {
213             this.logger.info(msgBuffer.toString(), t);
214         } else if ( logLevel == Logger.WARN ) {
215             this.logger.warn(msgBuffer.toString(), t);
216         } else if ( logLevel == Logger.TRACE_HIGH ) {
217             this.logger.info(msgBuffer.toString(), t);
218         } else if ( logLevel == Logger.TRACE_MEDIUM ) {
219             this.logger.debug(msgBuffer.toString(), t);
220         } else if ( logLevel == Logger.TRACE_LOW ) {
221             this.logger.debug(msgBuffer.toString(), t);
222         }
223     }
224 }
225
Popular Tags