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.ILoggerFactory;
37 import org.slf4j.spi.LoggerFactoryBinder;
38
39 /**
40 * The binding of {@link it.imolinfo.jbi4cics.Logger;Factory} class with an actual instance
41 * of {@link ILoggerFactory} is performed using information returned by this
42 * class.
43 * <p>
44 * This class also contains the information for binding
45 * {@link org.slf4j.MarkerFactory} with the appropriate
46 * {@link org.slf4j.IMarkerFactory} instance.
47 *
48 * @author Ceki Gülcü
49 * @author <a href="mailto:acannone@imolinfo.it">Amedeo Cannone</a>
50 * @author <a href="mailto:mcimatti@imolinfo.it">Marco Cimatti</a>
51 */
52 public final class StaticLoggerBinder implements LoggerFactoryBinder {
53
54 /**
55 * The unique instance of this class.
56 */
57 public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
58
59 /**
60 * The class name of the intended {@link ILoggerFactory} instance.
61 *
62 * @see #getLoggerFactoryClassStr()
63 */
64 private static final String LOGGER_FACTORY_CLASS_STR
65 = SINGLETON.loggerFactory.getClass().getName();
66
67 /**
68 * The <code>org.slf4j.ILoggerFactory</code> instance returned by the
69 * {@link #getLoggerFactory} method should always be the same object.
70 */
71 private final ILoggerFactory loggerFactory;
72
73 /**
74 * Initializes a new instance of this class. If available, Log4j will be
75 * used, else JDK 1.4+ logging will be used.
76 */
77 private StaticLoggerBinder() {
78 ILoggerFactory factory;
79
80 // We try to use Log4j: if not available, we use JDK 1.4 logging
81 try {
82 Class.forName("org.apache.log4j.Logger");
83 factory = new Log4jLoggerFactory();
84 } catch (ClassNotFoundException t) {
85 factory = new JDK14LoggerFactory();
86 }
87 loggerFactory = factory;
88 }
89
90 /**
91 * Return the instance of {@link ILoggerFactory} that
92 * {@link it.imolinfo.jbi4cics.Logger;Factory} class should bind to.
93 *
94 * @return the instance of {@link ILoggerFactory} that
95 * {@link it.imolinfo.jbi4cics.Logger;Factory} class should bind to.
96 */
97 public ILoggerFactory getLoggerFactory() {
98 return loggerFactory;
99 }
100
101 /**
102 * The <code>String</code> form of the {@link ILoggerFactory} object that
103 * this <code>LoggerFactoryBinder</code> instance is <em>intended</em> to
104 * return.
105 * <p>
106 * This method allows the developer to interogate this binder's intention
107 * which may be different from the {@link ILoggerFactory} instance it is
108 * able to yield in practice. The discrepency should only occur in case of
109 * errors.
110 *
111 * @return the class name of the intended {@link ILoggerFactory} instance.
112 */
113 public String getLoggerFactoryClassStr() {
114 return LOGGER_FACTORY_CLASS_STR;
115 }
116 }