View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.log4j.spi;
18  
19  import org.apache.log4j.Level;
20  import org.apache.log4j.Logger;
21  import org.apache.log4j.ULogger;
22  import org.apache.log4j.helpers.MessageFormatter;
23  
24  
25  /**
26   * An implementation of ULogger on org.apache.log4j.Logger.
27   */
28  public final class Log4JULogger implements ULogger {
29  
30      /**
31       * Wrapped log4j logger.
32       */
33      private final Logger logger;
34  
35      /**
36       * Create a new instance.
37       *
38       * @param l logger, may not be null.
39       */
40      public Log4JULogger(final Logger l) {
41          super();
42          if (l == null) {
43              throw new NullPointerException("l");
44          }
45          logger = l;
46      }
47  
48      /**
49       * {@inheritDoc}
50       */
51      public boolean isDebugEnabled() {
52          return logger.isDebugEnabled();
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      public void debug(final Object msg) {
59          logger.debug(msg);
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      public void debug(final Object parameterizedMsg,
66                        final Object param1) {
67          if (logger.isDebugEnabled()) {
68              logger.debug(MessageFormatter.format(
69                  parameterizedMsg.toString(), param1));
70          }
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      public void debug(final String parameterizedMsg,
77                        final Object param1,
78                        final Object param2) {
79          if (logger.isDebugEnabled()) {
80              logger.debug(MessageFormatter.format(
81                  parameterizedMsg, param1, param2));
82          }
83      }
84  
85      /**
86       * {@inheritDoc}
87       */
88      public void debug(final Object msg,
89                        final Throwable t) {
90          logger.debug(msg, t);
91      }
92  
93  
94      /**
95       * {@inheritDoc}
96       */
97      public boolean isInfoEnabled() {
98          return logger.isInfoEnabled();
99      }
100 
101     /**
102      * {@inheritDoc}
103      */
104     public void info(final Object msg) {
105         logger.info(msg);
106     }
107 
108 
109     /**
110      * {@inheritDoc}
111      */
112     public void info(final Object parameterizedMsg,
113                      final Object param1) {
114         if (logger.isInfoEnabled()) {
115             logger.info(MessageFormatter.format(
116                 parameterizedMsg.toString(), param1));
117         }
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     public void info(final String parameterizedMsg,
124                      final Object param1,
125                      final Object param2) {
126         if (logger.isInfoEnabled()) {
127             logger.info(MessageFormatter.format(
128                 parameterizedMsg,
129                 param1,
130                 param2));
131         }
132     }
133 
134     /**
135      * {@inheritDoc}
136      */
137     public void info(final Object msg, final Throwable t) {
138         logger.info(msg, t);
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     public boolean isWarnEnabled() {
145         return logger.isEnabledFor(Level.WARN);
146     }
147 
148     /**
149      * {@inheritDoc}
150      */
151     public void warn(final Object msg) {
152         logger.warn(msg);
153     }
154 
155     /**
156      * {@inheritDoc}
157      */
158     public void warn(final Object parameterizedMsg,
159                      final Object param1) {
160         if (logger.isEnabledFor(Level.WARN)) {
161             logger.warn(MessageFormatter.format(
162                 parameterizedMsg.toString(), param1));
163         }
164     }
165 
166     /**
167      * {@inheritDoc}
168      */
169     public void warn(final String parameterizedMsg,
170                      final Object param1,
171                      final Object param2) {
172         if (logger.isEnabledFor(Level.WARN)) {
173             logger.warn(MessageFormatter.format(
174                 parameterizedMsg, param1, param2));
175         }
176     }
177 
178     /**
179      * {@inheritDoc}
180      */
181     public void warn(final Object msg, final Throwable t) {
182         logger.warn(msg, t);
183     }
184 
185     /**
186      * {@inheritDoc}
187      */
188     public boolean isErrorEnabled() {
189         return logger.isEnabledFor(Level.ERROR);
190     }
191 
192     /**
193      * {@inheritDoc}
194      */
195     public void error(final Object msg) {
196         logger.error(msg);
197     }
198 
199 
200     /**
201      * {@inheritDoc}
202      */
203     public void error(final Object parameterizedMsg, final Object param1) {
204         if (logger.isEnabledFor(Level.ERROR)) {
205             logger.error(MessageFormatter.format(
206                 parameterizedMsg.toString(), param1));
207         }
208     }
209 
210     /**
211      * {@inheritDoc}
212      */
213     public void error(final String parameterizedMsg,
214                       final Object param1,
215                       final Object param2) {
216         if (logger.isEnabledFor(Level.ERROR)) {
217             logger.error(MessageFormatter.format(
218                 parameterizedMsg, param1, param2));
219         }
220     }
221 
222     /**
223      * {@inheritDoc}
224      */
225     public void error(final Object msg, final Throwable t) {
226         logger.error(msg, t);
227     }
228 
229 }