KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > util > CommonsLogger


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.util;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.util.*;
25
26 /**
27  * A logger class that strives to make it as easy as possible for
28  * developers to write log calls, while simultaneously making those
29  * calls as cheap as possible by performing lazy evaluation of the log
30  * message.<p>
31  *
32  * @author Marc Johnson (mjohnson at apache dot org)
33  * @author Glen Stampoultzis (glens at apache.org)
34  * @author Nicola Ken Barozzi (nicolaken at apache.org)
35  */

36
37 public class CommonsLogger extends POILogger
38 {
39
40     private static LogFactory _creator = LogFactory.getFactory();
41     private Log log = null;
42
43    
44     public void initialize(final String JavaDoc cat)
45     {
46         this.log = _creator.getInstance(cat);
47     }
48      
49     /**
50      * Log a message
51      *
52      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
53      * @param obj1 The object to log.
54      */

55
56     public void log(final int level, final Object JavaDoc obj1)
57     {
58         if(level==FATAL)
59         {
60           if(log.isFatalEnabled())
61           {
62             log.fatal(obj1);
63           }
64         }
65         else if(level==ERROR)
66         {
67           if(log.isErrorEnabled())
68           {
69             log.error(obj1);
70           }
71         }
72         else if(level==WARN)
73         {
74           if(log.isWarnEnabled())
75           {
76             log.warn(obj1);
77           }
78         }
79         else if(level==INFO)
80         {
81           if(log.isInfoEnabled())
82           {
83             log.info(obj1);
84           }
85         }
86         else if(level==DEBUG)
87         {
88           if(log.isDebugEnabled())
89           {
90             log.debug(obj1);
91           }
92         }
93         else
94         {
95           if(log.isTraceEnabled())
96           {
97             log.trace(obj1);
98           }
99         }
100
101     }
102
103     /**
104      * Check if a logger is enabled to log at the specified level
105      *
106      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
107      */

108
109     public boolean check(final int level)
110     {
111         if(level==FATAL)
112         {
113           if(log.isFatalEnabled())
114           {
115             return true;
116           }
117         }
118         else if(level==ERROR)
119         {
120           if(log.isErrorEnabled())
121           {
122             return true;
123           }
124         }
125         else if(level==WARN)
126         {
127           if(log.isWarnEnabled())
128           {
129             return true;
130           }
131         }
132         else if(level==INFO)
133         {
134           if(log.isInfoEnabled())
135           {
136             return true;
137           }
138         }
139         else if(level==DEBUG)
140         {
141           if(log.isDebugEnabled())
142           {
143             return true;
144           }
145         }
146
147         return false;
148
149     }
150
151  
152 } // end package scope class POILogger
153

154
Popular Tags