KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > slf4j > impl > JDK14LoggerFactory


1 /*
2  * Copyright (c) 2004-2005 SLF4J.ORG
3  * Copyright (c) 2004-2005 QOS.ch
4  *
5  * All rights reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, and/or sell copies of the Software, and to permit persons
12  * to whom the Software is furnished to do so, provided that the above
13  * copyright notice(s) and this permission notice appear in all copies of
14  * the Software and that both the above copyright notice(s) and this
15  * permission notice appear in supporting documentation.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
20  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
22  * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
23  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
24  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
25  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26  *
27  * Except as contained in this notice, the name of a copyright holder
28  * shall not be used in advertising or otherwise to promote the sale, use
29  * or other dealings in this Software without prior written authorization
30  * of the copyright holder.
31  *
32  */

33
34 package org.slf4j.impl;
35
36 import org.slf4j.Logger;
37 import org.slf4j.ILoggerFactory;
38
39 import java.util.HashMap JavaDoc;
40 import java.util.Map JavaDoc;
41
42 /**
43  * JDK14LoggerFactory is an implementation of {@link ILoggerFactory} returning
44  * the appropriately named {@link JDK14LoggerAdapter} instance.
45  *
46  * @author Ceki Gülcü
47  */

48 public class JDK14LoggerFactory implements ILoggerFactory {
49
50   // key: name (String), value: a JDK14LoggerAdapter;
51
Map JavaDoc loggerMap;
52
53   public JDK14LoggerFactory() {
54     loggerMap = new HashMap JavaDoc();
55   }
56
57   /*
58    * (non-Javadoc)
59    *
60    * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String)
61    */

62   public synchronized Logger getLogger(String JavaDoc name) {
63     Logger ulogger = null;
64     // protect against concurrent access of loggerMap
65
synchronized (this) {
66       // the root logger is called "" in JUL
67
if(name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {
68         name = "";
69       }
70       ulogger = (Logger) loggerMap.get(name);
71       if (ulogger == null) {
72         java.util.logging.Logger JavaDoc logger = java.util.logging.Logger
73             .getLogger(name);
74         ulogger = new JDK14LoggerAdapter(logger);
75         loggerMap.put(name, ulogger);
76       }
77     }
78     return ulogger;
79   }
80 }
81
Popular Tags