View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  package org.apache.james.container.spring.logging.log4j;
20  
21  import org.apache.log4j.Level;
22  import org.apache.log4j.Logger;
23  
24  
25  /**
26   * behaves like an avalon logger, but logs to log4j
27   */
28  public class AvalonToLog4jLogger implements org.apache.avalon.framework.logger.Logger {
29      private Logger logger;
30  
31      public AvalonToLog4jLogger(Logger logger) {
32          this.logger = logger;
33      }
34  
35      public void debug(String s) {
36          logger.debug(s);
37      }
38  
39      public void debug(String s, Throwable throwable) {
40          logger.debug(s, throwable);
41      }
42  
43      public boolean isDebugEnabled() {
44          return logger.isDebugEnabled();
45      }
46  
47      public void info(String s) {
48          logger.info(s);
49      }
50  
51      public void info(String s, Throwable throwable) {
52          logger.info(s, throwable);
53      }
54  
55      public boolean isInfoEnabled() {
56          return logger.isEnabledFor(Level.INFO);
57      }
58  
59      public void warn(String s) {
60          logger.warn(s);
61      }
62  
63      public void warn(String s, Throwable throwable) {
64          logger.warn(s, throwable);
65      }
66  
67      public boolean isWarnEnabled() {
68          return logger.isEnabledFor(Level.WARN);
69      }
70  
71      public void error(String s) {
72          logger.error(s);
73      }
74  
75      public void error(String s, Throwable throwable) {
76          logger.error(s, throwable);
77      }
78  
79      public boolean isErrorEnabled() {
80          return logger.isEnabledFor(Level.ERROR);
81      }
82  
83      public void fatalError(String s) {
84          logger.fatal(s);
85      }
86  
87      public void fatalError(String s, Throwable throwable) {
88          logger.fatal(s, throwable);
89      }
90  
91      public boolean isFatalErrorEnabled() {
92          return logger.isEnabledFor(Level.FATAL);
93      }
94  
95      public org.apache.avalon.framework.logger.Logger getChildLogger(String s) {
96          return new AvalonToLog4jLogger(Logger.getLogger(s));
97      }
98  }