1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.container.services.log;
1819import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogConfigurationException;
21import org.apache.commons.logging.LogFactory;
22import org.apache.pluto.services.log.LogService;
23import org.apache.pluto.services.log.Logger;
242526/***27 * Implements the logging service adaptor for the Pluto container 28 * adapting Jetspeed logging service implemented in Commons to Pluto29 * 30 * NOTE: this implementation may have performance issues31 * since everytime we call isSomethingEnabled, we must get a logger32 * 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 */38publicclassPlutoLogService39 implements LogService
40 {
41privatefinalstatic Log defaultLog = LogFactory.getLog(PlutoLogService.class);
42434445/* (non-Javadoc)46 * @see org.apache.pluto.services.log.LogService#getLogger(java.lang.String)47 */48public Logger getLogger(String component)
49 {
50returnnewContainerLoggerAdaptor(getConfiguredLogger(component));
51 }
5253/* (non-Javadoc)54 * @see org.apache.pluto.services.log.LogService#getLogger(java.lang.Class)55 */56public Logger getLogger(Class klass)
57 {
5859returnnewContainerLoggerAdaptor(getConfiguredLogger(klass));
60 }
6162/***63 * Given a string class name returns a logger for that class, or if we can't find a logger for the class64 * the it returns the default logger for this class65 * 66 * @param className67 * @return Log The logger configured for the given class name or the default logger if failed to load class68 */69private Log getConfiguredLogger(String className)
70 {
71 Class classe = null;
72 Log log = defaultLog;
7374try75 {
76 classe = Class.forName(className);
77 log = LogFactory.getLog(classe);
78 }
79catch (ClassNotFoundException e)
80 {
81// use the default logger82 }
83catch (LogConfigurationException e)
84 {
85// use the default logger 86 }
87return log;
88 }
8990/***91 * Given a string class name returns a logger for that class, or if we can't find a logger for the class92 * the it returns the default logger for this class93 * 94 * @param classe the class to get a logger for95 * @return Log The logger configured for the given class name or the default logger if failed to load class96 */97private Log getConfiguredLogger(Class classe)
98 {
99 Log log = defaultLog;
100101try102 {
103 log = LogFactory.getLog(classe);
104 }
105catch (LogConfigurationException e)
106 {
107// use the default logger 108 }
109return log;
110 }
111112 }