001package org.apache.maven.doxia.logging;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.codehaus.plexus.logging.Logger;
023
024/**
025 * Wrap a Plexus logger into a Doxia logger.
026 * Based on org.apache.maven.plugin.logging.Log.
027 *
028 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
029 * @since 1.1
030 */
031public class PlexusLoggerWrapper
032    implements Log
033{
034    private final Logger logger;
035
036    /**
037     * <p>Constructor for PlexusLoggerWrapper.</p>
038     *
039     * @param logger the Plexus logger to wrap.
040     */
041    public PlexusLoggerWrapper( Logger logger )
042    {
043        this.logger = logger;
044    }
045
046    /** {@inheritDoc} */
047    public void setLogLevel( int level )
048    {
049        if ( level <= LEVEL_DEBUG )
050        {
051            logger.setThreshold( Logger.LEVEL_DEBUG );
052        }
053        else if ( level <= LEVEL_INFO )
054        {
055            logger.setThreshold( Logger.LEVEL_INFO );
056        }
057        else if ( level <= LEVEL_WARN )
058        {
059            logger.setThreshold( Logger.LEVEL_WARN );
060        }
061        else if ( level <= LEVEL_ERROR )
062        {
063            logger.setThreshold( Logger.LEVEL_ERROR );
064        }
065        else
066        {
067            logger.setThreshold( Logger.LEVEL_DISABLED );
068        }
069    }
070
071    /**
072     * {@inheritDoc}
073     *
074     * @param content a {@link java.lang.CharSequence} object.
075     */
076    public void debug( CharSequence content )
077    {
078        logger.debug( toString( content ) );
079    }
080
081    /** {@inheritDoc} */
082    public void debug( CharSequence content, Throwable error )
083    {
084        logger.debug( toString( content ), error );
085    }
086
087    /** {@inheritDoc} */
088    public void debug( Throwable error )
089    {
090        logger.debug( "", error );
091    }
092
093    /** {@inheritDoc} */
094    public void info( CharSequence content )
095    {
096        logger.info( toString( content ) );
097    }
098
099    /** {@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}