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   * @version $Id: PlexusLoggerWrapper.java 785531 2009-06-17 09:47:59Z ltheussl $
30   * @since 1.1
31   */
32  public class PlexusLoggerWrapper
33      implements Log
34  {
35      private final Logger logger;
36  
37      /**
38       * <p>Constructor for PlexusLoggerWrapper.</p>
39       *
40       * @param logger the Plexus logger to wrap.
41       */
42      public PlexusLoggerWrapper( Logger logger )
43      {
44          this.logger = logger;
45      }
46  
47      /** {@inheritDoc} */
48      public void setLogLevel( int level )
49      {
50          if ( level <= LEVEL_DEBUG )
51          {
52              logger.setThreshold( Logger.LEVEL_DEBUG );
53          }
54          else if ( level <= LEVEL_INFO )
55          {
56              logger.setThreshold( Logger.LEVEL_INFO );
57          }
58          else if ( level <= LEVEL_WARN )
59          {
60              logger.setThreshold( Logger.LEVEL_WARN );
61          }
62          else if ( level <= LEVEL_ERROR )
63          {
64              logger.setThreshold( Logger.LEVEL_ERROR );
65          }
66          else
67          {
68              logger.setThreshold( Logger.LEVEL_DISABLED );
69          }
70      }
71  
72      /** {@inheritDoc} */
73      public void debug( CharSequence content )
74      {
75          logger.debug( toString( content ) );
76      }
77  
78      /** {@inheritDoc} */
79      public void debug( CharSequence content, Throwable error )
80      {
81          logger.debug( toString( content ), error );
82      }
83  
84      /** {@inheritDoc} */
85      public void debug( Throwable error )
86      {
87          logger.debug( "", error );
88      }
89  
90      /** {@inheritDoc} */
91      public void info( CharSequence content )
92      {
93          logger.info( toString( content ) );
94      }
95  
96      /** {@inheritDoc} */
97      public void info( CharSequence content, Throwable error )
98      {
99          logger.info( toString( content ), error );
100     }
101 
102     /** {@inheritDoc} */
103     public void info( Throwable error )
104     {
105         logger.info( "", error );
106     }
107 
108     /** {@inheritDoc} */
109     public void warn( CharSequence content )
110     {
111         logger.warn( toString( content ) );
112     }
113 
114     /** {@inheritDoc} */
115     public void warn( CharSequence content, Throwable error )
116     {
117         logger.warn( toString( content ), error );
118     }
119 
120     /** {@inheritDoc} */
121     public void warn( Throwable error )
122     {
123         logger.warn( "", error );
124     }
125 
126     /** {@inheritDoc} */
127     public void error( CharSequence content )
128     {
129         logger.error( toString( content ) );
130     }
131 
132     /** {@inheritDoc} */
133     public void error( CharSequence content, Throwable error )
134     {
135         logger.error( toString( content ), error );
136     }
137 
138     /** {@inheritDoc} */
139     public void error( Throwable error )
140     {
141         logger.error( "", error );
142     }
143 
144     /** {@inheritDoc} */
145     public boolean isDebugEnabled()
146     {
147         return logger.isDebugEnabled();
148     }
149 
150     /** {@inheritDoc} */
151     public boolean isInfoEnabled()
152     {
153         return logger.isInfoEnabled();
154     }
155 
156     /** {@inheritDoc} */
157     public boolean isWarnEnabled()
158     {
159         return logger.isWarnEnabled();
160     }
161 
162     /** {@inheritDoc} */
163     public boolean isErrorEnabled()
164     {
165         return logger.isErrorEnabled();
166     }
167 
168     // ----------------------------------------------------------------------
169     // Private methods
170     // ----------------------------------------------------------------------
171 
172     private String toString( CharSequence content )
173     {
174         if ( content == null )
175         {
176             return "";
177         }
178 
179         return content.toString();
180     }
181 }