View Javadoc
1   package org.apache.maven.doxia.logging;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.logging.Logger;
23  
24  /**
25   * Wrap a Plexus logger into a Doxia logger.
26   * Based on org.apache.maven.plugin.logging.Log.
27   *
28   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
29   * @since 1.1
30   */
31  public class PlexusLoggerWrapper
32      implements Log
33  {
34      private final Logger logger;
35  
36      /**
37       * <p>Constructor for PlexusLoggerWrapper.</p>
38       *
39       * @param logger the Plexus logger to wrap.
40       */
41      public PlexusLoggerWrapper( Logger logger )
42      {
43          this.logger = logger;
44      }
45  
46      /** {@inheritDoc} */
47      public void setLogLevel( int level )
48      {
49          if ( level <= LEVEL_DEBUG )
50          {
51              logger.setThreshold( Logger.LEVEL_DEBUG );
52          }
53          else if ( level <= LEVEL_INFO )
54          {
55              logger.setThreshold( Logger.LEVEL_INFO );
56          }
57          else if ( level <= LEVEL_WARN )
58          {
59              logger.setThreshold( Logger.LEVEL_WARN );
60          }
61          else if ( level <= LEVEL_ERROR )
62          {
63              logger.setThreshold( Logger.LEVEL_ERROR );
64          }
65          else
66          {
67              logger.setThreshold( Logger.LEVEL_DISABLED );
68          }
69      }
70  
71      /**
72       * {@inheritDoc}
73       *
74       * @param content a {@link java.lang.CharSequence} object.
75       */
76      public void debug( CharSequence content )
77      {
78          logger.debug( toString( content ) );
79      }
80  
81      /** {@inheritDoc} */
82      public void debug( CharSequence content, Throwable error )
83      {
84          logger.debug( toString( content ), error );
85      }
86  
87      /** {@inheritDoc} */
88      public void debug( Throwable error )
89      {
90          logger.debug( "", error );
91      }
92  
93      /** {@inheritDoc} */
94      public void info( CharSequence content )
95      {
96          logger.info( toString( content ) );
97      }
98  
99      /** {@inheritDoc} */
100     public void info( CharSequence content, Throwable error )
101     {
102         logger.info( toString( content ), error );
103     }
104 
105     /**
106      * {@inheritDoc}
107      *
108      * @param error a {@link java.lang.Throwable} object.
109      */
110     public void info( Throwable error )
111     {
112         logger.info( "", error );
113     }
114 
115     /**
116      * {@inheritDoc}
117      *
118      * @param content a {@link java.lang.CharSequence} object.
119      */
120     public void warn( CharSequence content )
121     {
122         logger.warn( toString( content ) );
123     }
124 
125     /** {@inheritDoc} */
126     public void warn( CharSequence content, Throwable error )
127     {
128         logger.warn( toString( content ), error );
129     }
130 
131     /** {@inheritDoc} */
132     public void warn( Throwable error )
133     {
134         logger.warn( "", error );
135     }
136 
137     /** {@inheritDoc} */
138     public void error( CharSequence content )
139     {
140         logger.error( toString( content ) );
141     }
142 
143     /** {@inheritDoc} */
144     public void error( CharSequence content, Throwable error )
145     {
146         logger.error( toString( content ), error );
147     }
148 
149     /**
150      * {@inheritDoc}
151      *
152      * @param error a {@link java.lang.Throwable} object.
153      */
154     public void error( Throwable error )
155     {
156         logger.error( "", error );
157     }
158 
159     /**
160      * {@inheritDoc}
161      *
162      * @return a boolean.
163      */
164     public boolean isDebugEnabled()
165     {
166         return logger.isDebugEnabled();
167     }
168 
169     /**
170      * {@inheritDoc}
171      *
172      * @return a boolean.
173      */
174     public boolean isInfoEnabled()
175     {
176         return logger.isInfoEnabled();
177     }
178 
179     /**
180      * {@inheritDoc}
181      *
182      * @return a boolean.
183      */
184     public boolean isWarnEnabled()
185     {
186         return logger.isWarnEnabled();
187     }
188 
189     /**
190      * {@inheritDoc}
191      *
192      * @return a boolean.
193      */
194     public boolean isErrorEnabled()
195     {
196         return logger.isErrorEnabled();
197     }
198 
199     // ----------------------------------------------------------------------
200     // Private methods
201     // ----------------------------------------------------------------------
202 
203     private String toString( CharSequence content )
204     {
205         if ( content == null )
206         {
207             return "";
208         }
209 
210         return content.toString();
211     }
212 }