Coverage Report - org.apache.maven.doxia.logging.SystemStreamLog
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemStreamLog
0%
0/71
0%
0/40
1,8
 
 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 java.io.PrintWriter;
 23  
 import java.io.StringWriter;
 24  
 
 25  
 /**
 26  
  * Logger with "standard" output and error output stream. The log prefix is voluntarily in lower case.
 27  
  * <br/>
 28  
  * Based on <code>org.apache.maven.plugin.logging.SystemStreamLog</code>.
 29  
  *
 30  
  * @author jdcasey
 31  
  * @author ltheussl
 32  
  * @version $Id: SystemStreamLog.java 733395 2009-01-10 23:09:40Z ltheussl $
 33  
  * @since 1.1
 34  
  */
 35  0
 public class SystemStreamLog
 36  
     implements Log
 37  
 {
 38  0
     private static final String EOL = System.getProperty( "line.separator" );
 39  
 
 40  0
     private int currentLevel = LEVEL_INFO;
 41  
 
 42  
     /** {@inheritDoc} */
 43  
     public void setLogLevel( int level )
 44  
     {
 45  0
         if ( level <= LEVEL_DEBUG )
 46  
         {
 47  0
             currentLevel = LEVEL_DEBUG;
 48  
         }
 49  0
         else if ( level <= LEVEL_INFO )
 50  
         {
 51  0
             currentLevel = LEVEL_INFO;
 52  
         }
 53  0
         else if ( level <= LEVEL_WARN )
 54  
         {
 55  0
             currentLevel = LEVEL_WARN;
 56  
         }
 57  0
         else if ( level <= LEVEL_ERROR )
 58  
         {
 59  0
             currentLevel = LEVEL_ERROR;
 60  
         }
 61  
         else
 62  
         {
 63  0
             currentLevel = LEVEL_DISABLED;
 64  
         }
 65  0
     }
 66  
 
 67  
     /** {@inheritDoc} */
 68  
     public void debug( CharSequence content )
 69  
     {
 70  0
         if ( isDebugEnabled() )
 71  
         {
 72  0
             print( "debug", content );
 73  
         }
 74  0
     }
 75  
 
 76  
     /** {@inheritDoc} */
 77  
     public void debug( CharSequence content, Throwable error )
 78  
     {
 79  0
         if ( isDebugEnabled() )
 80  
         {
 81  0
             print( "debug", content, error );
 82  
         }
 83  0
     }
 84  
 
 85  
     /** {@inheritDoc} */
 86  
     public void debug( Throwable error )
 87  
     {
 88  0
         if ( isDebugEnabled() )
 89  
         {
 90  0
             print( "debug", error );
 91  
         }
 92  0
     }
 93  
 
 94  
     /** {@inheritDoc} */
 95  
     public void info( CharSequence content )
 96  
     {
 97  0
         if ( isInfoEnabled() )
 98  
         {
 99  0
             print( "info", content );
 100  
         }
 101  0
     }
 102  
 
 103  
     /** {@inheritDoc} */
 104  
     public void info( CharSequence content, Throwable error )
 105  
     {
 106  0
         if ( isInfoEnabled() )
 107  
         {
 108  0
             print( "info", content, error );
 109  
         }
 110  0
     }
 111  
 
 112  
     /** {@inheritDoc} */
 113  
     public void info( Throwable error )
 114  
     {
 115  0
         if ( isInfoEnabled() )
 116  
         {
 117  0
             print( "info", error );
 118  
         }
 119  0
     }
 120  
 
 121  
     /** {@inheritDoc} */
 122  
     public void warn( CharSequence content )
 123  
     {
 124  0
         if ( isWarnEnabled() )
 125  
         {
 126  0
             print( "warn", content );
 127  
         }
 128  0
     }
 129  
 
 130  
     /** {@inheritDoc} */
 131  
     public void warn( CharSequence content, Throwable error )
 132  
     {
 133  0
         if ( isWarnEnabled() )
 134  
         {
 135  0
             print( "warn", content, error );
 136  
         }
 137  0
     }
 138  
 
 139  
     /** {@inheritDoc} */
 140  
     public void warn( Throwable error )
 141  
     {
 142  0
         if ( isWarnEnabled() )
 143  
         {
 144  0
             print( "warn", error );
 145  
         }
 146  0
     }
 147  
 
 148  
     /** {@inheritDoc} */
 149  
     public void error( CharSequence content )
 150  
     {
 151  0
         if ( isErrorEnabled() )
 152  
         {
 153  0
             System.err.println( "[error] " + content.toString() );
 154  
         }
 155  0
     }
 156  
 
 157  
     /** {@inheritDoc} */
 158  
     public void error( CharSequence content, Throwable error )
 159  
     {
 160  0
         if ( isErrorEnabled() )
 161  
         {
 162  0
             StringWriter sWriter = new StringWriter();
 163  0
             PrintWriter pWriter = new PrintWriter( sWriter );
 164  
 
 165  0
             error.printStackTrace( pWriter );
 166  
 
 167  0
             System.err.println( "[error] " + content.toString()
 168  
                 + EOL + EOL + sWriter.toString() );
 169  
         }
 170  0
     }
 171  
 
 172  
     /** {@inheritDoc} */
 173  
     public void error( Throwable error )
 174  
     {
 175  0
         if ( isErrorEnabled() )
 176  
         {
 177  0
             StringWriter sWriter = new StringWriter();
 178  0
             PrintWriter pWriter = new PrintWriter( sWriter );
 179  
 
 180  0
             error.printStackTrace( pWriter );
 181  
 
 182  0
             System.err.println( "[error] " + sWriter.toString() );
 183  
         }
 184  0
     }
 185  
 
 186  
     /** {@inheritDoc} */
 187  
     public boolean isDebugEnabled()
 188  
     {
 189  0
         return ( currentLevel <= LEVEL_DEBUG );
 190  
     }
 191  
 
 192  
     /** {@inheritDoc} */
 193  
     public boolean isInfoEnabled()
 194  
     {
 195  0
         return ( currentLevel <= LEVEL_INFO );
 196  
     }
 197  
 
 198  
     /** {@inheritDoc} */
 199  
     public boolean isWarnEnabled()
 200  
     {
 201  0
         return ( currentLevel <= LEVEL_WARN );
 202  
     }
 203  
 
 204  
     /** {@inheritDoc} */
 205  
     public boolean isErrorEnabled()
 206  
     {
 207  0
         return ( currentLevel <= LEVEL_ERROR );
 208  
     }
 209  
 
 210  
       //
 211  
      // private
 212  
     //
 213  
 
 214  
     private void print( String prefix, CharSequence content )
 215  
     {
 216  0
         System.out.println( "[" + prefix + "] " + content.toString() );
 217  0
     }
 218  
 
 219  
     private void print( String prefix, Throwable error )
 220  
     {
 221  0
         StringWriter sWriter = new StringWriter();
 222  0
         PrintWriter pWriter = new PrintWriter( sWriter );
 223  
 
 224  0
         error.printStackTrace( pWriter );
 225  
 
 226  0
         System.out.println( "[" + prefix + "] " + sWriter.toString() );
 227  0
     }
 228  
 
 229  
     private void print( String prefix, CharSequence content, Throwable error )
 230  
     {
 231  0
         StringWriter sWriter = new StringWriter();
 232  0
         PrintWriter pWriter = new PrintWriter( sWriter );
 233  
 
 234  0
         error.printStackTrace( pWriter );
 235  
 
 236  0
         System.out.println( "[" + prefix + "] " + content.toString()
 237  
             + EOL + EOL + sWriter.toString() );
 238  0
     }
 239  
 }