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   */
29  public final class ConsoleLogger extends AbstractLogger {
30      public ConsoleLogger(int threshold, String name) {
31          super(threshold, name);
32      }
33  
34      public void debug(String message, Throwable throwable) {
35          if (isDebugEnabled()) {
36              System.out.print("[DEBUG] ");
37              System.out.println(message);
38  
39              if (null != throwable) {
40                  throwable.printStackTrace(System.out);
41              }
42          }
43      }
44  
45      public void info(String message, Throwable throwable) {
46          if (isInfoEnabled()) {
47              System.out.print("[INFO] ");
48              System.out.println(message);
49  
50              if (null != throwable) {
51                  throwable.printStackTrace(System.out);
52              }
53          }
54      }
55  
56      public void warn(String message, Throwable throwable) {
57          if (isWarnEnabled()) {
58              System.out.print("[WARNING] ");
59              System.out.println(message);
60  
61              if (null != throwable) {
62                  throwable.printStackTrace(System.out);
63              }
64          }
65      }
66  
67      public void error(String message, Throwable throwable) {
68          if (isErrorEnabled()) {
69              System.out.print("[ERROR] ");
70              System.out.println(message);
71  
72              if (null != throwable) {
73                  throwable.printStackTrace(System.out);
74              }
75          }
76      }
77  
78      public void fatalError(String message, Throwable throwable) {
79          if (isFatalErrorEnabled()) {
80              System.out.print("[FATAL ERROR] ");
81              System.out.println(message);
82  
83              if (null != throwable) {
84                  throwable.printStackTrace(System.out);
85              }
86          }
87      }
88  
89      public Logger getChildLogger(String name) {
90          return this;
91      }
92  }