01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * Implements the logging service adaptor for the Pluto container
27: * adapting Jetspeed logging service implemented in Commons to Pluto
28: *
29: * NOTE: this implementation may have performance issues
30: * since everytime we call isSomethingEnabled, we must get a logger
31: * I recommend deprecated Pluto's logging container service and
32: * this adaptor once we get the Pluto source in Apache's CVS
33: *
34: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
35: * @version $Id: PlutoLogService.java 516448 2007-03-09 16:25:47Z ate $
36: */
37: public class PlutoLogService implements LogService {
38: private final static Log defaultLog = LogFactory
39: .getLog(PlutoLogService.class);
40:
41: /* (non-Javadoc)
42: * @see org.apache.pluto.services.log.LogService#getLogger(java.lang.String)
43: */
44: public Logger getLogger(String component) {
45: return new ContainerLoggerAdaptor(
46: getConfiguredLogger(component));
47: }
48:
49: /* (non-Javadoc)
50: * @see org.apache.pluto.services.log.LogService#getLogger(java.lang.Class)
51: */
52: public Logger getLogger(Class klass) {
53:
54: return new ContainerLoggerAdaptor(getConfiguredLogger(klass));
55: }
56:
57: /**
58: * Given a string class name returns a logger for that class, or if we can't find a logger for the class
59: * the it returns the default logger for this class
60: *
61: * @param className
62: * @return Log The logger configured for the given class name or the default logger if failed to load class
63: */
64: private Log getConfiguredLogger(String className) {
65: Class classe = null;
66: Log log = defaultLog;
67:
68: try {
69: classe = Class.forName(className);
70: log = LogFactory.getLog(classe);
71: } catch (ClassNotFoundException e) {
72: // use the default logger
73: } catch (LogConfigurationException e) {
74: // use the default logger
75: }
76: return log;
77: }
78:
79: /**
80: * Given a string class name returns a logger for that class, or if we can't find a logger for the class
81: * the it returns the default logger for this class
82: *
83: * @param classe the class to get a logger for
84: * @return Log The logger configured for the given class name or the default logger if failed to load class
85: */
86: private Log getConfiguredLogger(Class classe) {
87: Log log = defaultLog;
88:
89: try {
90: log = LogFactory.getLog(classe);
91: } catch (LogConfigurationException e) {
92: // use the default logger
93: }
94: return log;
95: }
96:
97: }
|