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 it.imolinfo.jbi4cics.jbi.Messages;
37 import java.util.MissingResourceException;
38 import org.slf4j.ILoggerFactory;
39 import it.imolinfo.jbi4cics.Logger;
40
41 /**
42 * <code>JDK14LoggerFactory</code> is an implementation of
43 * {@link ILoggerFactory} returning the appropriately named
44 * {@link JDK14LoggerAdapter} instance.
45 * <p>
46 *
47 * @author Ceki Gülcü
48 * @author <a href="mailto:acannone@imolinfo.it">Amedeo Cannone</a>
49 * @author <a href="mailto:mcimatti@imolinfo.it">Marco Cimatti</a>
50 */
51 final class JDK14LoggerFactory implements ILoggerFactory {
52
53 /**
54 * Creates a new instance of this class.
55 */
56 JDK14LoggerFactory() {
57 }
58
59 /**
60 * Return an appropriate <code>org.slf4j.Logger</code> instance as
61 * specified by the <code>name</code> parameter.
62 * <p>
63 * If <code>name</code> is equal to the string value <code>"NULL"</code>
64 * (case insensitive), then the root logger of the underlying logging system
65 * is returned.
66 * <p>
67 * Null-valued name arguments are considered invalid.
68 * <p>
69 * Certain extremely simple logging systems, e.g. NOP, may always return the
70 * same logger instance regardless of the requested name.
71 *
72 * @param name
73 * the name of the Logger to return.
74 * @return the <code>org.slf4j.Logger</code> instance as specified by
75 * <code>name</code>.
76 */
77 public Logger getLogger(final String name) {
78 java.util.logging.Logger logger;
79 Messages messages;
80
81 // The root logger is called "" in JUL
82 if (name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {
83 logger = java.util.logging.Logger.getLogger("");
84 } else {
85 logger = java.util.logging.Logger.getLogger(name);
86 }
87
88 // If name identifies a Class, there may be an associated resource
89 // bundle to apply I18N
90 try {
91 Class clazz = Class.forName(name);
92
93 messages = Messages.getMessages(clazz);
94 } catch (ClassNotFoundException e) {
95 messages = null;
96 } catch (MissingResourceException e) {
97 messages = null;
98 }
99 return new JDK14LoggerAdapter(logger, messages);
100 }
101 }