View Javadoc

1   /*
2   The MIT License
3   
4   Copyright (c) 2004, The Codehaus
5   
6   Permission is hereby granted, free of charge, to any person obtaining a copy of
7   this software and associated documentation files (the "Software"), to deal in
8   the Software without restriction, including without limitation the rights to
9   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  of the Software, and to permit persons to whom the Software is furnished to do
11  so, subject to the following conditions:
12  
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15  
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23   */
24  package org.codehaus.mojo.scmchangelog.scm.util;
25  
26  import org.apache.maven.plugin.logging.Log;
27  import org.apache.maven.scm.log.ScmLogger;
28  
29  /**
30   * Implementation of ScmLogger using org.apache.maven.plugin.logging.Log.
31   * @author ehsavoie
32   * @version $Id: JavaScmLogger.java 7652 2008-09-11 07:58:40Z ehsavoie $
33   * @see org.apache.maven.scm.log.ScmLogger
34   */
35  public class MavenScmLogger
36          implements ScmLogger
37  {
38      /**
39       * The 'real' logger implementation.s
40       */
41      private Log logger;
42  
43      /**
44       * Create a new MavenScmLogger (ScmLoger that wraps a maven Log)
45       * @param logger the 'real' logger to be wrapped as a ScmLogger.
46       */
47      public MavenScmLogger( Log logger )
48      {
49          if ( isColorized() )
50          {
51              this.logger = new ColorConsoleLogger( logger );
52          }
53          else
54          {
55              this.logger = logger;
56          }        
57      }
58  
59      /** {@inheritDoc} */
60      public boolean isDebugEnabled()
61      {
62          return logger.isDebugEnabled();
63      }
64  
65      /** {@inheritDoc} */
66      public void debug( String content )
67      {
68          logger.debug( content );
69      }
70  
71      /** {@inheritDoc} */
72      public void debug( String content, Throwable error )
73      {
74          logger.debug( content, error );
75      }
76  
77      /** {@inheritDoc} */
78      public void debug( Throwable error )
79      {
80          logger.debug( error );
81      }
82  
83      /** {@inheritDoc} */
84      public boolean isInfoEnabled()
85      {
86          return logger.isInfoEnabled();
87      }
88  
89      /** {@inheritDoc} */
90      public void info( String content )
91      {
92          logger.info( content );
93      }
94  
95      /** {@inheritDoc} */
96      public void info( String content, Throwable error )
97      {
98          logger.info( content, error );
99      }
100 
101     /** {@inheritDoc} */
102     public void info( Throwable error )
103     {
104         logger.info( error );
105     }
106 
107     /** {@inheritDoc} */
108     public boolean isWarnEnabled()
109     {
110         return logger.isWarnEnabled();
111     }
112 
113     /** {@inheritDoc} */
114     public void warn( String content )
115     {
116         logger.warn( content );
117     }
118 
119     /** {@inheritDoc} */
120     public void warn( String content, Throwable error )
121     {
122         logger.warn( content, error );
123     }
124 
125     /** {@inheritDoc} */
126     public void warn( Throwable error )
127     {
128         logger.warn( error );
129     }
130 
131     /** {@inheritDoc} */
132     public boolean isErrorEnabled()
133     {
134         return logger.isErrorEnabled();
135     }
136 
137     /** {@inheritDoc} */
138     public void error( String content )
139     {
140         logger.error( content );
141     }
142 
143     /** {@inheritDoc} */
144     public void error( String content, Throwable error )
145     {
146         logger.error( content, error );
147     }
148 
149     /** {@inheritDoc} */
150     public void error( Throwable error )
151     {
152         logger.error( error );
153     }
154 
155     /**
156      * Indicates if th logs will be ANSI colorized.
157      * @return true if there will be colors - false otherwise.
158      */
159     private boolean isColorized()
160     {
161         return System.getProperty( "colorized.console" ) != null;
162     }
163 }