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   * @version $Id$
26   */
27  public abstract class AbstractLogger
28          implements Logger
29  {
30      private int threshold;
31  
32      private String name;
33  
34      public AbstractLogger( int threshold, String name )
35      {
36          if ( !isValidThreshold( threshold ) )
37          {
38              throw new IllegalArgumentException( "Threshold " + threshold + " is not valid" );
39          }
40  
41          this.threshold = threshold;
42          this.name = name;
43      }
44  
45      public int getThreshold()
46      {
47          return threshold;
48      }
49  
50      public void setThreshold( int threshold )
51      {
52          this.threshold = threshold;
53      }
54  
55      public String getName()
56      {
57          return name;
58      }
59  
60      public void debug( String message )
61      {
62          debug( message, null );
63      }
64  
65      public boolean isDebugEnabled()
66      {
67          return threshold <= LEVEL_DEBUG;
68      }
69  
70      public void info( String message )
71      {
72          info( message, null );
73      }
74  
75      public boolean isInfoEnabled()
76      {
77          return threshold <= LEVEL_INFO;
78      }
79  
80      public void warn( String message )
81      {
82          warn( message, null );
83      }
84  
85      public boolean isWarnEnabled()
86      {
87          return threshold <= LEVEL_WARN;
88      }
89  
90      public void error( String message )
91      {
92          error( message, null );
93      }
94  
95      public boolean isErrorEnabled()
96      {
97          return threshold <= LEVEL_ERROR;
98      }
99  
100     public void fatalError( String message )
101     {
102         fatalError( message, null );
103     }
104 
105     public boolean isFatalErrorEnabled()
106     {
107         return threshold <= LEVEL_FATAL;
108     }
109 
110     protected boolean isValidThreshold( int threshold )
111     {
112         if ( threshold == LEVEL_DEBUG )
113         {
114             return true;
115         }
116         if ( threshold == LEVEL_INFO )
117         {
118             return true;
119         }
120         if ( threshold == LEVEL_WARN )
121         {
122             return true;
123         }
124         if ( threshold == LEVEL_ERROR )
125         {
126             return true;
127         }
128         if ( threshold == LEVEL_FATAL )
129         {
130             return true;
131         }
132         if ( threshold == LEVEL_DISABLED )
133         {
134             return true;
135         }
136 
137         return false;
138     }
139 }