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: import java.util.*;
21:
22: /**
23: * Provides logging without clients having to mess with
24: * configuration/initialization.
25: *
26: * @author Andrew C. Oliver (acoliver at apache dot org)
27: * @author Marc Johnson (mjohnson at apache dot org)
28: * @author Nicola Ken Barozzi (nicolaken at apache.org)
29: */
30:
31: public class POILogFactory {
32:
33: // map of POILogger instances, with classes as keys
34: private static Map _loggers = new HashMap();;
35:
36: /**
37: * construct a POILogFactory.
38: */
39:
40: private POILogFactory() {
41: }
42:
43: /**
44: * Get a logger, based on a class name
45: *
46: * @param theclass the class whose name defines the log
47: *
48: * @return a POILogger for the specified class
49: */
50:
51: public static POILogger getLogger(final Class theclass) {
52: return getLogger(theclass.getName());
53: }
54:
55: /**
56: * Get a logger, based on a String
57: *
58: * @param cat the String that defines the log
59: *
60: * @return a POILogger for the specified class
61: */
62:
63: public static POILogger getLogger(final String cat) {
64: POILogger logger = null;
65:
66: if (_loggers.containsKey(cat)) {
67: logger = (POILogger) _loggers.get(cat);
68: } else {
69: try {
70: String loggerClassName = System
71: .getProperty("org.apache.poi.util.POILogger");
72: Class loggerClass = Class.forName(loggerClassName);
73: logger = (POILogger) loggerClass.newInstance();
74: } catch (Exception e) {
75:
76: logger = new NullLogger();
77: }
78:
79: logger.initialize(cat);
80:
81: _loggers.put(cat, logger);
82: }
83: return logger;
84: }
85:
86: } // end public class POILogFactory
|