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.components.slide.impl;
018:
019: import org.apache.avalon.framework.logger.Logger;
020:
021: /**
022: * The class represent an adapter for the logger for jakarta slide
023: *
024: * @version CVS $Id: SlideLoggerAdapter.java 433543 2006-08-22 06:22:54Z crossley $
025: */
026: public class SlideLoggerAdapter implements
027: org.apache.slide.util.logger.Logger {
028: private Logger logger;
029: private int currentLogLevel = ERROR;
030:
031: public SlideLoggerAdapter(Logger logger) {
032: this .logger = logger;
033: }
034:
035: public void log(Object data, Throwable t, String channel, int level) {
036: if (level == CRITICAL) {
037: this .logger.fatalError(data.toString(), t);
038: } else if (level == ERROR) {
039: this .logger.error(data.toString(), t);
040: } else if (level == WARNING) {
041: this .logger.warn(data.toString(), t);
042: } else if (level == INFO) {
043: this .logger.info(data.toString(), t);
044: } else if (level == DEBUG) {
045: this .logger.debug(data.toString(), t);
046: } else {
047: this .logger.error(data.toString(), t);
048: }
049: }
050:
051: /**
052: * Log an object thru the specified channel and with the specified level.
053: *
054: * @param data The object to log.
055: * @param channel The channel name used for logging.
056: * @param level The level used for logging.
057: */
058: public void log(Object data, String channel, int level) {
059: if (level == CRITICAL) {
060: this .logger.fatalError(data.toString());
061: } else if (level == ERROR) {
062: this .logger.error(data.toString());
063: } else if (level == WARNING) {
064: this .logger.warn(data.toString());
065: } else if (level == INFO) {
066: this .logger.info(data.toString());
067: } else if (level == DEBUG) {
068: this .logger.debug(data.toString());
069: } else {
070: this .logger.error(data.toString());
071: }
072: }
073:
074: /**
075: * Log an object with the specified level.
076: *
077: * @param data The object to log.
078: * @param level The level used for logging.
079: */
080: public void log(Object data, int level) {
081: if (level == CRITICAL) {
082: this .logger.fatalError(data.toString());
083: } else if (level == ERROR) {
084: this .logger.error(data.toString());
085: } else if (level == WARNING) {
086: this .logger.warn(data.toString());
087: } else if (level == INFO) {
088: this .logger.info(data.toString());
089: } else if (level == DEBUG) {
090: this .logger.debug(data.toString());
091: } else {
092: this .logger.error(data.toString());
093: }
094: }
095:
096: /**
097: * Log an object.
098: *
099: * @param data The object to log.
100: */
101: public void log(Object data) {
102: if (currentLogLevel == CRITICAL) {
103: this .logger.fatalError(data.toString());
104: } else if (currentLogLevel == ERROR) {
105: this .logger.error(data.toString());
106: } else if (currentLogLevel == WARNING) {
107: this .logger.warn(data.toString());
108: } else if (currentLogLevel == INFO) {
109: this .logger.info(data.toString());
110: } else if (currentLogLevel == DEBUG) {
111: this .logger.debug(data.toString());
112: } else {
113: this .logger.error(data.toString());
114: }
115: }
116:
117: /**
118: * Set the logger level for the default channel
119: *
120: * @param level the logger level
121: */
122: public void setLoggerLevel(int level) {
123: currentLogLevel = level;
124: }
125:
126: /**
127: * Set the logger level for the specified channel
128: *
129: * @param channel
130: * @param level the logger level
131: */
132: public void setLoggerLevel(String channel, int level) {
133: currentLogLevel = level;
134: }
135:
136: /**
137: * Get the logger level for the default channel
138: * @return logger level
139: */
140: public int getLoggerLevel() {
141: return currentLogLevel;
142: }
143:
144: /**
145: * Get the logger level for the specified channel
146: *
147: * @param channel the channel
148: * @return logger level
149: */
150: public int getLoggerLevel(String channel) {
151: if (this .logger.isDebugEnabled()) {
152: return DEBUG;
153: } else if (this .logger.isInfoEnabled()) {
154: return INFO;
155: } else if (this .logger.isWarnEnabled()) {
156: return WARNING;
157: } else if (this .logger.isErrorEnabled()) {
158: return ERROR;
159: } else if (this .logger.isFatalErrorEnabled()) {
160: return CRITICAL;
161: } else {
162: return ERROR;
163: }
164: }
165:
166: /**
167: * Check if the channel with the specified level is enabled for logging.
168: *
169: * @param channel The channel specification
170: * @param level The level specification
171: */
172: public boolean isEnabled(String channel, int level) {
173: if (this .logger.isDebugEnabled()) {
174: return DEBUG <= level;
175: } else if (this .logger.isInfoEnabled()) {
176: return INFO <= level;
177: } else if (this .logger.isWarnEnabled()) {
178: return WARNING <= level;
179: } else if (this .logger.isErrorEnabled()) {
180: return ERROR <= level;
181: } else if (this .logger.isFatalErrorEnabled()) {
182: return CRITICAL <= level;
183: } else {
184: return ERROR <= level;
185: }
186: }
187:
188: /**
189: * Check if the default channel with the specified level is enabled for logging.
190: *
191: * @param level The level specification
192: */
193: public boolean isEnabled(int level) {
194: if (this.logger.isDebugEnabled()) {
195: return DEBUG <= level;
196: } else if (this.logger.isInfoEnabled()) {
197: return INFO <= level;
198: } else if (this.logger.isWarnEnabled()) {
199: return WARNING <= level;
200: } else if (this.logger.isErrorEnabled()) {
201: return ERROR <= level;
202: } else if (this.logger.isFatalErrorEnabled()) {
203: return CRITICAL <= level;
204: } else {
205: return ERROR <= level;
206: }
207: }
208:
209: }
|