KickJava   Java API By Example, From Geeks To Geeks.

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


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
22
23 /**
24  * A logger class that strives to make it as easy as possible for
25  * developers to write log calls, while simultaneously making those
26  * calls as cheap as possible by performing lazy evaluation of the log
27  * message.
28  *
29  * @author Marc Johnson (mjohnson at apache dot org)
30  * @author Glen Stampoultzis (glens at apache.org)
31  * @author Nicola Ken Barozzi (nicolaken at apache.org)
32  */

33 public class SystemOutLogger extends POILogger
34 {
35     private String JavaDoc cat;
36
37     public void initialize(final String JavaDoc cat)
38     {
39        this.cat=cat;
40     }
41
42     /**
43      * Log a message
44      *
45      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
46      * @param obj1 The object to log.
47      */

48
49     public void log(final int level, final Object JavaDoc obj1)
50     {
51         if (check(level))
52             System.out.println("["+cat+"] "+obj1);
53     }
54
55     /**
56      * Check if a logger is enabled to log at the specified level
57      *
58      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
59      * @see #DEBUG
60      * @see #INFO
61      * @see #WARN
62      * @see #ERROR
63      * @see #FATAL
64      */

65     public boolean check(final int level)
66     {
67         int currentLevel = Integer.parseInt(System.getProperty("poi.log.level", WARN + ""));
68         if (level >= currentLevel)
69             return true;
70         else
71             return false;
72     }
73
74
75 } // end package scope class POILogger
76

77
Popular Tags