KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.FileInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 import java.util.*;
25
26 /**
27  * Provides logging without clients having to mess with
28  * configuration/initialization.
29  *
30  * @author Andrew C. Oliver (acoliver at apache dot org)
31  * @author Marc Johnson (mjohnson at apache dot org)
32  * @author Nicola Ken Barozzi (nicolaken at apache.org)
33  */

34
35 public class POILogFactory
36 {
37
38     // map of POILogger instances, with classes as keys
39
private static Map _loggers = new HashMap();;
40
41
42     /**
43      * construct a POILogFactory.
44      */

45
46     private POILogFactory()
47     {
48     }
49
50     /**
51      * Get a logger, based on a class name
52      *
53      * @param theclass the class whose name defines the log
54      *
55      * @return a POILogger for the specified class
56      */

57
58     public static POILogger getLogger(final Class JavaDoc theclass)
59     {
60         return getLogger(theclass.getName());
61     }
62     
63     /**
64      * Get a logger, based on a String
65      *
66      * @param cat the String that defines the log
67      *
68      * @return a POILogger for the specified class
69      */

70
71     public static POILogger getLogger(final String JavaDoc cat)
72     {
73         POILogger logger = null;
74
75         if (_loggers.containsKey(cat))
76         {
77             logger = ( POILogger ) _loggers.get(cat);
78         }
79         else
80         {
81             try{
82               String JavaDoc loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
83               Class JavaDoc loggerClass = Class.forName(loggerClassName);
84               logger = ( POILogger ) loggerClass.newInstance();
85             }
86             catch(Exception JavaDoc e){
87             
88               logger = new NullLogger();
89             }
90             
91             logger.initialize(cat);
92             
93             _loggers.put(cat, logger);
94         }
95         return logger;
96     }
97         
98 } // end public class POILogFactory
99
Popular Tags