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 * @version $Id$ 030 * @since 1.1 031 */ 032public class PlexusLoggerWrapper 033 implements Log 034{ 035 private final Logger logger; 036 037 /** 038 * <p>Constructor for PlexusLoggerWrapper.</p> 039 * 040 * @param logger the Plexus logger to wrap. 041 */ 042 public PlexusLoggerWrapper( Logger logger ) 043 { 044 this.logger = logger; 045 } 046 047 /** {@inheritDoc} */ 048 public void setLogLevel( int level ) 049 { 050 if ( level <= LEVEL_DEBUG ) 051 { 052 logger.setThreshold( Logger.LEVEL_DEBUG ); 053 } 054 else if ( level <= LEVEL_INFO ) 055 { 056 logger.setThreshold( Logger.LEVEL_INFO ); 057 } 058 else if ( level <= LEVEL_WARN ) 059 { 060 logger.setThreshold( Logger.LEVEL_WARN ); 061 } 062 else if ( level <= LEVEL_ERROR ) 063 { 064 logger.setThreshold( Logger.LEVEL_ERROR ); 065 } 066 else 067 { 068 logger.setThreshold( Logger.LEVEL_DISABLED ); 069 } 070 } 071 072 /** {@inheritDoc} */ 073 public void debug( CharSequence content ) 074 { 075 logger.debug( toString( content ) ); 076 } 077 078 /** {@inheritDoc} */ 079 public void debug( CharSequence content, Throwable error ) 080 { 081 logger.debug( toString( content ), error ); 082 } 083 084 /** {@inheritDoc} */ 085 public void debug( Throwable error ) 086 { 087 logger.debug( "", error ); 088 } 089 090 /** {@inheritDoc} */ 091 public void info( CharSequence content ) 092 { 093 logger.info( toString( content ) ); 094 } 095 096 /** {@inheritDoc} */ 097 public void info( CharSequence content, Throwable error ) 098 { 099 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}