1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.util;
18
19 import net.sf.asterisk.util.impl.JavaLoggingLog;
20 import net.sf.asterisk.util.impl.Log4JLogger;
21 import net.sf.asterisk.util.impl.NullLog;
22
23 /***
24 * Facade to hide details of the underlying logging system.
25 *
26 * @author srt
27 * @version $Id: LogFactory.java,v 1.2 2005/04/20 18:22:13 srt Exp $
28 */
29 public final class LogFactory
30 {
31 /***
32 * Indicates if log4j is available on the classpath or not. If the
33 * check has not yet performed this is <code>null</code>.
34 */
35 private static Boolean log4jLoggingAvailable = null;
36
37 /***
38 * Indicates if java.util.logging is available on the classpath or not. If the
39 * check has not yet performed this is <code>null</code>.
40 */
41 private static Boolean javaLoggingAvailable = null;
42
43 /***
44 * Returns an instance of Log suitable for logging from the given class.
45 *
46 * @param clazz the class to create the logger for.
47 * @return the created logger.
48 */
49 public static Log getLog(Class clazz)
50 {
51 if (log4jLoggingAvailable == null)
52 {
53 try
54 {
55 Class.forName("org.apache.log4j.Logger");
56 log4jLoggingAvailable = Boolean.TRUE;
57 }
58 catch (Exception e)
59 {
60 log4jLoggingAvailable = Boolean.FALSE;
61 }
62 }
63 if (log4jLoggingAvailable.booleanValue())
64 {
65 return new Log4JLogger(clazz);
66 }
67 else
68 {
69 if (javaLoggingAvailable == null)
70 {
71 try
72 {
73 Class.forName("java.util.logging.Logger");
74 javaLoggingAvailable = Boolean.TRUE;
75 }
76 catch (Exception e)
77 {
78 javaLoggingAvailable = Boolean.FALSE;
79 }
80 }
81 if (javaLoggingAvailable.booleanValue())
82 {
83 return new JavaLoggingLog(clazz);
84 }
85 else
86 {
87 return new NullLog();
88 }
89 }
90 }
91 }