KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > slide > impl > SlideLoggerAdapter


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.components.slide.impl;
17
18 import org.apache.avalon.framework.logger.Logger;
19
20 /**
21  * The class represent an adapter for the logger for jakarta slide
22  *
23  * @version CVS $Id: SlideLoggerAdapter.java 30932 2004-07-29 17:35:38Z vgritsenko $
24  */

25 public class SlideLoggerAdapter implements org.apache.slide.util.logger.Logger {
26     private Logger logger;
27     private int currentLogLevel = ERROR;
28
29     public SlideLoggerAdapter(Logger logger) {
30         this.logger = logger;
31     }
32
33     public void log(Object JavaDoc data, Throwable JavaDoc t, String JavaDoc channel, int level) {
34         if (level==CRITICAL) {
35             this.logger.fatalError(data.toString(),t);
36         } else if (level==ERROR) {
37             this.logger.error(data.toString(),t);
38         } else if (level==WARNING) {
39             this.logger.warn(data.toString(),t);
40         } else if (level==INFO) {
41             this.logger.info(data.toString(),t);
42         } else if (level==DEBUG) {
43             this.logger.debug(data.toString(),t);
44         } else {
45             this.logger.error(data.toString(),t);
46         }
47     }
48
49     /**
50      * Log an object thru the specified channel and with the specified level.
51      *
52      * @param data The object to log.
53      * @param channel The channel name used for logging.
54      * @param level The level used for logging.
55      */

56     public void log(Object JavaDoc data, String JavaDoc channel, int level) {
57         if (level==CRITICAL) {
58             this.logger.fatalError(data.toString());
59         } else if (level==ERROR) {
60             this.logger.error(data.toString());
61         } else if (level==WARNING) {
62             this.logger.warn(data.toString());
63         } else if (level==INFO) {
64             this.logger.info(data.toString());
65         } else if (level==DEBUG) {
66             this.logger.debug(data.toString());
67         } else {
68             this.logger.error(data.toString());
69         }
70     }
71
72     /**
73      * Log an object with the specified level.
74      *
75      * @param data The object to log.
76      * @param level The level used for logging.
77      */

78     public void log(Object JavaDoc data, int level) {
79         if (level==CRITICAL) {
80             this.logger.fatalError(data.toString());
81         } else if (level==ERROR) {
82             this.logger.error(data.toString());
83         } else if (level==WARNING) {
84             this.logger.warn(data.toString());
85         } else if (level==INFO) {
86             this.logger.info(data.toString());
87         } else if (level==DEBUG) {
88             this.logger.debug(data.toString());
89         } else {
90             this.logger.error(data.toString());
91         }
92     }
93
94     /**
95      * Log an object.
96      *
97      * @param data The object to log.
98      */

99     public void log(Object JavaDoc data) {
100        if (currentLogLevel==CRITICAL) {
101            this.logger.fatalError(data.toString());
102        } else if (currentLogLevel==ERROR) {
103            this.logger.error(data.toString());
104        } else if (currentLogLevel==WARNING) {
105            this.logger.warn(data.toString());
106        } else if (currentLogLevel==INFO) {
107            this.logger.info(data.toString());
108        } else if (currentLogLevel==DEBUG) {
109            this.logger.debug(data.toString());
110        } else {
111            this.logger.error(data.toString());
112        }
113     }
114
115     /**
116      * Set the logger level for the default channel
117      *
118      * @param level the logger level
119      */

120     public void setLoggerLevel(int level) {
121         currentLogLevel = level;
122     }
123
124     /**
125      * Set the logger level for the specified channel
126      *
127      * @param channel
128      * @param level the logger level
129      */

130     public void setLoggerLevel(String JavaDoc channel, int level) {
131         currentLogLevel = level;
132     }
133
134     /**
135      * Get the logger level for the default channel
136      * @return logger level
137      */

138     public int getLoggerLevel() {
139         return currentLogLevel;
140     }
141
142     /**
143      * Get the logger level for the specified channel
144      *
145      * @param channel the channel
146      * @return logger level
147      */

148     public int getLoggerLevel(String JavaDoc channel) {
149         if (this.logger.isDebugEnabled()) {
150             return DEBUG;
151         } else if (this.logger.isInfoEnabled()) {
152             return INFO;
153         } else if (this.logger.isWarnEnabled()) {
154             return WARNING;
155         } else if (this.logger.isErrorEnabled()) {
156             return ERROR;
157         } else if (this.logger.isFatalErrorEnabled() ) {
158             return CRITICAL;
159         } else {
160             return ERROR;
161         }
162     }
163
164     /**
165      * Check if the channel with the specified level is enabled for logging.
166      *
167      * @param channel The channel specification
168      * @param level The level specification
169      */

170     public boolean isEnabled(String JavaDoc channel, int level) {
171         if (this.logger.isDebugEnabled()) {
172             return DEBUG<=level;
173         } else if (this.logger.isInfoEnabled()) {
174             return INFO<=level;
175         } else if (this.logger.isWarnEnabled()) {
176             return WARNING<=level;
177         } else if (this.logger.isErrorEnabled()) {
178             return ERROR<=level;
179         } else if (this.logger.isFatalErrorEnabled() ) {
180             return CRITICAL<=level;
181         } else {
182             return ERROR<=level;
183         }
184     }
185
186     /**
187      * Check if the default channel with the specified level is enabled for logging.
188      *
189      * @param level The level specification
190      */

191     public boolean isEnabled(int level) {
192         if (this.logger.isDebugEnabled()) {
193             return DEBUG<=level;
194         } else if (this.logger.isInfoEnabled()) {
195             return INFO<=level;
196         } else if (this.logger.isWarnEnabled()) {
197             return WARNING<=level;
198         } else if (this.logger.isErrorEnabled()) {
199             return ERROR<=level;
200         } else if (this.logger.isFatalErrorEnabled() ) {
201             return CRITICAL<=level;
202         } else {
203             return ERROR<=level;
204         }
205     }
206
207 }
208
209
Popular Tags