01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.util;
19:
20: /**
21: * A logger class that strives to make it as easy as possible for
22: * developers to write log calls, while simultaneously making those
23: * calls as cheap as possible by performing lazy evaluation of the log
24: * message.
25: *
26: * @author Marc Johnson (mjohnson at apache dot org)
27: * @author Glen Stampoultzis (glens at apache.org)
28: * @author Nicola Ken Barozzi (nicolaken at apache.org)
29: */
30: public class SystemOutLogger extends POILogger {
31: private String cat;
32:
33: public void initialize(final String cat) {
34: this .cat = cat;
35: }
36:
37: /**
38: * Log a message
39: *
40: * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
41: * @param obj1 The object to log.
42: */
43:
44: public void log(final int level, final Object obj1) {
45: if (check(level))
46: System.out.println("[" + cat + "] " + obj1);
47: }
48:
49: /**
50: * Check if a logger is enabled to log at the specified level
51: *
52: * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
53: * @see #DEBUG
54: * @see #INFO
55: * @see #WARN
56: * @see #ERROR
57: * @see #FATAL
58: */
59: public boolean check(final int level) {
60: int currentLevel;
61: try {
62: currentLevel = Integer.parseInt(System.getProperty(
63: "poi.log.level", WARN + ""));
64: } catch (SecurityException e) {
65: currentLevel = POILogger.DEBUG;
66: }
67:
68: if (level >= currentLevel)
69: return true;
70: else
71: return false;
72: }
73:
74: } // end package scope class POILogger
|