1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container.services.log;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogConfigurationException;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.pluto.services.log.LogService;
23 import org.apache.pluto.services.log.Logger;
24
25
26 /***
27 * Implements the logging service adaptor for the Pluto container
28 * adapting Jetspeed logging service implemented in Commons to Pluto
29 *
30 * NOTE: this implementation may have performance issues
31 * since everytime we call isSomethingEnabled, we must get a logger
32 * I recommend deprecated Pluto's logging container service and
33 * this adaptor once we get the Pluto source in Apache's CVS
34 *
35 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
36 * @version $Id: PlutoLogService.java 516448 2007-03-09 16:25:47Z ate $
37 */
38 public class PlutoLogService
39 implements LogService
40 {
41 private final static Log defaultLog = LogFactory.getLog(PlutoLogService.class);
42
43
44
45
46
47
48 public Logger getLogger(String component)
49 {
50 return new ContainerLoggerAdaptor(getConfiguredLogger(component));
51 }
52
53
54
55
56 public Logger getLogger(Class klass)
57 {
58
59 return new ContainerLoggerAdaptor(getConfiguredLogger(klass));
60 }
61
62 /***
63 * Given a string class name returns a logger for that class, or if we can't find a logger for the class
64 * the it returns the default logger for this class
65 *
66 * @param className
67 * @return Log The logger configured for the given class name or the default logger if failed to load class
68 */
69 private Log getConfiguredLogger(String className)
70 {
71 Class classe = null;
72 Log log = defaultLog;
73
74 try
75 {
76 classe = Class.forName(className);
77 log = LogFactory.getLog(classe);
78 }
79 catch (ClassNotFoundException e)
80 {
81
82 }
83 catch (LogConfigurationException e)
84 {
85
86 }
87 return log;
88 }
89
90 /***
91 * Given a string class name returns a logger for that class, or if we can't find a logger for the class
92 * the it returns the default logger for this class
93 *
94 * @param classe the class to get a logger for
95 * @return Log The logger configured for the given class name or the default logger if failed to load class
96 */
97 private Log getConfiguredLogger(Class classe)
98 {
99 Log log = defaultLog;
100
101 try
102 {
103 log = LogFactory.getLog(classe);
104 }
105 catch (LogConfigurationException e)
106 {
107
108 }
109 return log;
110 }
111
112 }