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.adaptor;
20  
21  import org.apache.avalon.framework.logger.Logger;
22  import org.apache.james.container.spring.logging.LoggerToComponentMapper;
23  import org.apache.james.container.spring.logging.LogWorker;
24  
25  /**
26   * bridge to act as a Avalon logger but effectively forward to a some other logging service
27   */
28  public class LoggingBridge implements Logger, LoggerToComponentMapper {
29      public static final String LEVEL_DEBUG = "debug";
30      public static final String LEVEL_INFO  = "info";
31      public static final String LEVEL_WARN  = "warn";
32      public static final String LEVEL_ERROR = "error";
33      public static final String LEVEL_FATAL = "fatal";
34  
35      private boolean m_debugEnabled = true;
36      private LogWorker logWorker;
37  
38      public void setLogWorker(LogWorker logWorker) {
39          this.logWorker = logWorker;
40      }
41  
42      public Logger getComponentLogger(String beanName) {
43          return this; // every bean gets the same logger, could be more finegrained
44      }
45  
46      protected void forwardLogMessage(String level, String message) {
47          logWorker.logMessage(level, message);
48      }
49  
50      protected void forwardLogException(String level, String message, Throwable exception) {
51          logWorker.logException(level, message, exception);
52      }
53  
54      public org.apache.avalon.framework.logger.Logger getChildLogger(java.lang.String string) {
55          return this;
56      }
57  
58      public void debug(java.lang.String string) {
59          forwardLogMessage(LEVEL_DEBUG, string);
60      }
61  
62      public void debug(java.lang.String string, java.lang.Throwable throwable) {
63          forwardLogException(LEVEL_DEBUG, string, throwable);
64      }
65  
66      public boolean isDebugEnabled() {
67          return m_debugEnabled;
68      }
69  
70      public void disableDebug() {
71          m_debugEnabled = false;
72      }
73  
74      public void info(java.lang.String string) {
75          forwardLogMessage(LEVEL_INFO, string);
76      }
77  
78      public void info(java.lang.String string, java.lang.Throwable throwable) {
79          forwardLogException(LEVEL_INFO, string, throwable);
80      }
81  
82      public boolean isInfoEnabled() {
83          return true;
84      }
85  
86      public void warn(java.lang.String string) {
87          forwardLogMessage(LEVEL_WARN, string);
88      }
89  
90      public void warn(java.lang.String string, java.lang.Throwable throwable) {
91          forwardLogException(LEVEL_WARN, string, throwable);
92      }
93  
94      public boolean isWarnEnabled() {
95          return true;
96      }
97  
98      public void error(java.lang.String string) {
99          forwardLogMessage(LEVEL_ERROR, string);
100     }
101 
102     public void error(java.lang.String string, java.lang.Throwable throwable) {
103         forwardLogException(LEVEL_ERROR, string, throwable);
104     }
105 
106     public boolean isErrorEnabled() {
107         return true;
108     }
109 
110     public void fatalError(java.lang.String string) {
111         forwardLogMessage(LEVEL_FATAL, string);
112     }
113 
114     public void fatalError(java.lang.String string, java.lang.Throwable throwable) {
115         forwardLogException(LEVEL_FATAL, string, throwable);
116     }
117 
118     public boolean isFatalErrorEnabled() {
119         return true;
120     }
121 
122 
123 }