View Javadoc
1   package org.codehaus.plexus.logging;
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  /*
20   * LICENSE
21   */
22  
23  /**
24   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
25   */
26  public abstract class AbstractLogger implements Logger {
27      private int threshold;
28  
29      private String name;
30  
31      public AbstractLogger(int threshold, String name) {
32          if (!isValidThreshold(threshold)) {
33              throw new IllegalArgumentException("Threshold " + threshold + " is not valid");
34          }
35  
36          this.threshold = threshold;
37          this.name = name;
38      }
39  
40      public int getThreshold() {
41          return threshold;
42      }
43  
44      public void setThreshold(int threshold) {
45          this.threshold = threshold;
46      }
47  
48      public String getName() {
49          return name;
50      }
51  
52      public void debug(String message) {
53          debug(message, null);
54      }
55  
56      public boolean isDebugEnabled() {
57          return threshold <= LEVEL_DEBUG;
58      }
59  
60      public void info(String message) {
61          info(message, null);
62      }
63  
64      public boolean isInfoEnabled() {
65          return threshold <= LEVEL_INFO;
66      }
67  
68      public void warn(String message) {
69          warn(message, null);
70      }
71  
72      public boolean isWarnEnabled() {
73          return threshold <= LEVEL_WARN;
74      }
75  
76      public void error(String message) {
77          error(message, null);
78      }
79  
80      public boolean isErrorEnabled() {
81          return threshold <= LEVEL_ERROR;
82      }
83  
84      public void fatalError(String message) {
85          fatalError(message, null);
86      }
87  
88      public boolean isFatalErrorEnabled() {
89          return threshold <= LEVEL_FATAL;
90      }
91  
92      protected boolean isValidThreshold(int threshold) {
93          if (threshold == LEVEL_DEBUG) {
94              return true;
95          }
96          if (threshold == LEVEL_INFO) {
97              return true;
98          }
99          if (threshold == LEVEL_WARN) {
100             return true;
101         }
102         if (threshold == LEVEL_ERROR) {
103             return true;
104         }
105         if (threshold == LEVEL_FATAL) {
106             return true;
107         }
108         if (threshold == LEVEL_DISABLED) {
109             return true;
110         }
111 
112         return false;
113     }
114 }