View Javadoc
1   package org.codehaus.plexus.logging.console;
2   
3   /*
4    * Copyright 2001-2006 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.logging.AbstractLogger;
20  import org.codehaus.plexus.logging.Logger;
21  
22  /**
23   * Logger sending everything to the standard output streams.
24   * This is mainly for the cases when you have a utility that
25   * does not have a logger to supply.
26   *
27   * @author <a href="mailto:dev@avalon.codehaus.org">Avalon Development Team</a>
28   * @version $Id$
29   */
30  public final class ConsoleLogger
31      extends AbstractLogger
32  {
33      public ConsoleLogger( int threshold, String name )
34      {
35          super( threshold, name );
36      }
37  
38      public void debug( String message, Throwable throwable )
39      {
40          if ( isDebugEnabled() )
41          {
42              System.out.print( "[DEBUG] " );
43              System.out.println( message );
44  
45              if ( null != throwable )
46              {
47                  throwable.printStackTrace( System.out );
48              }
49          }
50      }
51  
52      public void info( String message, Throwable throwable )
53      {
54          if ( isInfoEnabled() )
55          {
56              System.out.print( "[INFO] " );
57              System.out.println( message );
58  
59              if ( null != throwable )
60              {
61                  throwable.printStackTrace( System.out );
62              }
63          }
64      }
65  
66      public void warn( String message, Throwable throwable )
67      {
68          if ( isWarnEnabled() )
69          {
70              System.out.print( "[WARNING] " );
71              System.out.println( message );
72  
73              if ( null != throwable )
74              {
75                  throwable.printStackTrace( System.out );
76              }
77          }
78      }
79  
80      public void error( String message, Throwable throwable )
81      {
82          if ( isErrorEnabled() )
83          {
84              System.out.print( "[ERROR] " );
85              System.out.println( message );
86  
87              if ( null != throwable )
88              {
89                  throwable.printStackTrace( System.out );
90              }
91          }
92      }
93  
94      public void fatalError( String message, Throwable throwable )
95      {
96          if ( isFatalErrorEnabled() )
97          {
98              System.out.print( "[FATAL ERROR] " );
99              System.out.println( message );
100 
101             if ( null != throwable )
102             {
103                 throwable.printStackTrace( System.out );
104             }
105         }
106     }
107 
108     public Logger getChildLogger( String name )
109     {
110         return this;
111     }
112 }