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.jsieve.mailet;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.mailet.base.GenericMailet;
23  
24  /**
25   * Adapts commons logging to mailet logging.
26   */
27  class CommonsLoggingAdapter implements Log {
28      
29      public static final int TRACE = 6;
30      public static final int DEBUG = 5;
31      public static final int INFO = 4;
32      public static final int WARN = 3;
33      public static final int ERROR = 2;
34      public static final int FATAL = 1;
35      
36      private final GenericMailet mailet;
37      private final int level;
38      
39      public CommonsLoggingAdapter(final GenericMailet mailet, final int level) {
40          super();
41          this.mailet = mailet;
42          this.level = level;
43      }
44  
45      public void debug(Object message) {
46          if (isDebugEnabled()) {
47              mailet.log(message == null ? "NULL" : message.toString());
48          }
49      }
50  
51      public void debug(Object message, Throwable t) {
52          if (isDebugEnabled()) {
53              mailet.log(message == null ? "NULL" : message.toString(), t);
54          } 
55      }
56  
57      public void error(Object message) {
58          if (isErrorEnabled()) {
59              mailet.log(message == null ? "NULL" : message.toString());
60          }
61      }
62  
63      public void error(Object message, Throwable t) {
64          if (isErrorEnabled()) {
65              mailet.log(message == null ? "NULL" : message.toString(), t);
66          }
67      }
68  
69      public void fatal(Object message) {
70          if (isFatalEnabled()) {
71              mailet.log(message == null ? "NULL" : message.toString());
72          }
73      }
74  
75      public void fatal(Object message, Throwable t) {
76          if (isFatalEnabled()) {
77              mailet.log(message == null ? "NULL" : message.toString(), t);
78          }
79      }
80  
81      public void info(Object message) {
82          if (isInfoEnabled()) {
83              mailet.log(message == null ? "NULL" : message.toString());
84          }
85      }
86  
87      public void info(Object message, Throwable t) {
88          if (isInfoEnabled()) {
89              mailet.log(message == null ? "NULL" : message.toString(), t);
90          }
91      }
92  
93      public boolean isDebugEnabled() {
94          return level <= DEBUG;
95      }
96  
97      public boolean isErrorEnabled() {
98          return level <= ERROR;
99      }
100 
101     public boolean isFatalEnabled() {
102         return level <= FATAL;
103     }
104 
105     public boolean isInfoEnabled() {
106         return level <= INFO;
107     }
108 
109     public boolean isTraceEnabled() {
110         return level <= TRACE;
111     }
112 
113     public boolean isWarnEnabled() {
114         return level <= WARN;
115     }
116 
117     public void trace(Object message) {
118         if (isTraceEnabled()) {
119             mailet.log(message == null ? "NULL" : message.toString());
120         }
121     }
122 
123     public void trace(Object message, Throwable t) {
124         if (isTraceEnabled()) {
125             mailet.log(message == null ? "NULL" : message.toString(), t);
126         }
127     }
128 
129     public void warn(Object message) {
130         if (isWarnEnabled()) {
131             mailet.log(message == null ? "NULL" : message.toString());
132         }
133     }
134 
135     public void warn(Object message, Throwable t) {
136         if (isWarnEnabled()) {
137             mailet.log(message == null ? "NULL" : message.toString(), t);
138         }
139     }
140     
141     
142 }