View Javadoc

1   /*
2    ~ Copyright 2006-2007 Nicolas De Loof.
3    ~
4    ~ Licensed under the Apache License, Version 2.0 (the "License");
5    ~ you may not use this file except in compliance with the License.
6    ~ You may obtain a copy of the License at
7    ~
8    ~      http://www.apache.org/licenses/LICENSE-2.0
9    ~
10   ~ Unless required by applicable law or agreed to in writing, software
11   ~ distributed under the License is distributed on an "AS IS" BASIS,
12   ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   ~ See the License for the specific language governing permissions and
14   ~ limitations under the License.
15   */
16  package org.jmonit.log;
17  
18  import org.apache.log4j.Priority;
19  
20  /**
21   * <code>Logger</code> implementation that delegates to log4j loggers.
22   * <p>
23   * Use the deprecate <code>Priority</code> constants for compatibility with
24   * earlyer versions of log4j.
25   * 
26   * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
27   */
28  public class Log4jLogger
29      extends Log
30  {
31  
32      /** The fully qualified name of the Log4JLogger class. */
33      private static final String FQCN = Log4jLogger.class.getName();
34  
35      /** log4j delegate */
36      private org.apache.log4j.Logger logger;
37  
38      /**
39       * Constructor
40       * 
41       * @param caller target logging class
42       */
43      public Log4jLogger( Class caller )
44      {
45          super();
46          this.logger = org.apache.log4j.Logger.getLogger( caller );
47      }
48  
49      /**
50       * {@inheritDoc}
51       * 
52       * @see info.jmonit.logger.Log#isDebugEnabled()
53       */
54      public boolean isDebugEnabled()
55      {
56          return logger.isDebugEnabled();
57      }
58  
59      /**
60       * {@inheritDoc}
61       * 
62       * @see info.jmonit.logger.Log#debug(java.lang.String)
63       */
64      public void debug( String message )
65      {
66          logger.log( FQCN, Priority.DEBUG, message, null );
67      }
68  
69      /**
70       * {@inheritDoc}
71       * 
72       * @see info.jmonit.logger.Log#info(java.lang.String)
73       */
74      public void info( String message )
75      {
76          logger.log( FQCN, Priority.INFO, message, null );
77      }
78  
79      /**
80       * {@inheritDoc}
81       * 
82       * @see info.jmonit.logger.Log#info(java.lang.String, Throwable)
83       */
84      public void info( String message, Throwable t )
85      {
86          logger.log( FQCN, Priority.INFO, message, t );
87      }
88  
89      /**
90       * {@inheritDoc}
91       * 
92       * @see info.jmonit.logger.Log#error(java.lang.String)
93       */
94      public void error( String message )
95      {
96          logger.log( FQCN, Priority.ERROR, message, null );
97      }
98  
99      /**
100      * {@inheritDoc}
101      * 
102      * @see info.jmonit.logger.Log#error(java.lang.String, Throwable)
103      */
104     public void error( String message, Throwable t )
105     {
106         logger.log( FQCN, Priority.ERROR, message, t );
107     }
108 
109     /**
110      * {@inheritDoc}
111      * 
112      * @see info.jmonit.logger.Log#warn(java.lang.String)
113      */
114     public void warn( String message )
115     {
116         logger.log( FQCN, Priority.WARN, message, null );
117     }
118 
119     /**
120      * {@inheritDoc}
121      * 
122      * @see info.jmonit.logger.Log#warn(java.lang.String, Throwable)
123      */
124     public void warn( String message, Throwable t )
125     {
126         logger.log( FQCN, Priority.WARN, message, t );
127     }
128 }