001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.wsrp.logging;
018:
019: import org.apache.wsrp4j.log.Logger;
020:
021: /**
022: * A wrapper for the cocoon logger<br/>
023: *
024: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
025: * @author <a href="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
026: *
027: * @version $Id: WSRPLogger.java 433543 2006-08-22 06:22:54Z crossley $
028: */
029: public class WSRPLogger implements Logger {
030:
031: /** The avalon logger */
032: protected final org.apache.avalon.framework.logger.Logger logger;
033:
034: /**
035: * constructor<br/>
036: *
037: * @param logger
038: */
039: public WSRPLogger(org.apache.avalon.framework.logger.Logger logger) {
040: this .logger = logger;
041: }
042:
043: /**
044: * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String)
045: */
046: public void entry(int logLevel, String loggingMethod) {
047: this .entry(logLevel, loggingMethod, null);
048: }
049:
050: /**
051: * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String, java.lang.Object)
052: */
053: public void entry(int logLevel, String loggingMethod, Object parm1) {
054: this .entry(logLevel, loggingMethod, new Object[] { parm1 });
055: }
056:
057: /**
058: * @see org.apache.wsrp4j.log.Logger#entry(int, java.lang.String, java.lang.Object[])
059: */
060: public void entry(int logLevel, String loggingMethod, Object[] parms) {
061: this .text(logLevel, loggingMethod, "Entering method", parms);
062: }
063:
064: /**
065: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String)
066: */
067: public void exit(int logLevel, String loggingMethod) {
068: this .text(logLevel, loggingMethod, "Exiting method.");
069: }
070:
071: /**
072: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, byte)
073: */
074: public void exit(int logLevel, String loggingMethod, byte retValue) {
075: this .exit(logLevel, loggingMethod, new Byte(retValue));
076: }
077:
078: /**
079: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, short)
080: */
081: public void exit(int logLevel, String loggingMethod, short retValue) {
082: this .exit(logLevel, loggingMethod, new Short(retValue));
083: }
084:
085: /**
086: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, int)
087: */
088: public void exit(int logLevel, String loggingMethod, int retValue) {
089: this .exit(logLevel, loggingMethod, new Integer(retValue));
090: }
091:
092: /**
093: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, long)
094: */
095: public void exit(int logLevel, String loggingMethod, long retValue) {
096: this .exit(logLevel, loggingMethod, new Long(retValue));
097: }
098:
099: /**
100: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, float)
101: */
102: public void exit(int logLevel, String loggingMethod, float retValue) {
103: this .exit(logLevel, loggingMethod, new Float(retValue));
104: }
105:
106: /**
107: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, double)
108: */
109: public void exit(int logLevel, String loggingMethod, double retValue) {
110: this .exit(logLevel, loggingMethod, new Double(retValue));
111: }
112:
113: /**
114: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, char)
115: */
116: public void exit(int logLevel, String loggingMethod, char retValue) {
117: this .exit(logLevel, loggingMethod, new Character(retValue));
118: }
119:
120: /**
121: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, boolean)
122: */
123: public void exit(int logLevel, String loggingMethod,
124: boolean retValue) {
125: this .exit(logLevel, loggingMethod, new Boolean(retValue));
126: }
127:
128: /**
129: * @see org.apache.wsrp4j.log.Logger#exit(int, java.lang.String, java.lang.Object)
130: */
131: public void exit(int logLevel, String loggingMethod, Object retValue) {
132: this .text(logLevel, loggingMethod,
133: "Exiting method. Returned value: {0}", retValue);
134: }
135:
136: /**
137: * @see org.apache.wsrp4j.log.Logger#isLogging(int)
138: */
139: public boolean isLogging(int logLevel) {
140: if (logLevel == Logger.ERROR) {
141: return this .logger.isErrorEnabled();
142: } else if (logLevel == Logger.INFO) {
143: return this .logger.isInfoEnabled();
144: } else if (logLevel == Logger.WARN) {
145: return this .logger.isWarnEnabled();
146: } else if (logLevel == Logger.TRACE_HIGH) {
147: return this .logger.isInfoEnabled();
148: } else if (logLevel == Logger.TRACE_MEDIUM) {
149: return this .logger.isDebugEnabled();
150: } else if (logLevel == Logger.TRACE_LOW) {
151: return this .logger.isDebugEnabled();
152: }
153: return false;
154: }
155:
156: /**
157: * @see org.apache.wsrp4j.log.Logger#stackTrace(int, java.lang.String, java.lang.String)
158: */
159: public void stackTrace(int logLevel, String loggingMethod,
160: String text) {
161: this .text(logLevel, loggingMethod, new Throwable("Stacktrace"),
162: text);
163: }
164:
165: /**
166: * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String)
167: */
168: public void text(int logLevel, String loggingMethod, String text) {
169: this .text(logLevel, loggingMethod, text, null);
170: }
171:
172: /**
173: * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String, java.lang.Object)
174: */
175: public void text(int logLevel, String loggingMethod, String text,
176: Object parm1) {
177: this
178: .text(logLevel, loggingMethod, text,
179: new Object[] { parm1 });
180: }
181:
182: /**
183: * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.String, java.lang.Object[])
184: */
185: public void text(int logLevel, String loggingMethod, String text,
186: Object[] parms) {
187: this .text(logLevel, loggingMethod, (Throwable) null, text,
188: parms);
189: }
190:
191: /**
192: * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.Throwable, java.lang.String)
193: */
194: public void text(int logLevel, String loggingMethod, Throwable t,
195: String text) {
196: this .text(logLevel, loggingMethod, t, text, null);
197: }
198:
199: /**
200: * @see org.apache.wsrp4j.log.Logger#text(int, java.lang.String, java.lang.Throwable, java.lang.String, java.lang.Object[])
201: */
202: public void text(int logLevel, String loggingMethod, Throwable t,
203: String text, Object[] parms) {
204: if (!this .isLogging(logLevel)) {
205: return;
206: }
207: StringBuffer msgBuffer = new StringBuffer();
208: if (loggingMethod != null) {
209: msgBuffer.append(loggingMethod);
210: msgBuffer.append(" - ");
211: }
212: if (text != null) {
213: msgBuffer.append(text);
214: }
215: if (parms != null) {
216: msgBuffer.append("\nParameters:\n");
217: for (int i = 0; i < parms.length; i++) {
218: msgBuffer.append(parms[i]);
219: }
220: }
221:
222: if (logLevel == Logger.ERROR) {
223: this.logger.error(msgBuffer.toString(), t);
224: } else if (logLevel == Logger.INFO) {
225: this.logger.info(msgBuffer.toString(), t);
226: } else if (logLevel == Logger.WARN) {
227: this.logger.warn(msgBuffer.toString(), t);
228: } else if (logLevel == Logger.TRACE_HIGH) {
229: this.logger.info(msgBuffer.toString(), t);
230: } else if (logLevel == Logger.TRACE_MEDIUM) {
231: this.logger.debug(msgBuffer.toString(), t);
232: } else if (logLevel == Logger.TRACE_LOW) {
233: this.logger.debug(msgBuffer.toString(), t);
234: }
235: }
236: }
|