01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.kfs.context;
17:
18: import java.net.URL;
19: import java.net.URLClassLoader;
20:
21: import org.apache.log4j.Logger;
22: import org.apache.log4j.PropertyConfigurator;
23: import org.kuali.kfs.KFSConstants;
24:
25: public class Log4jConfigurer {
26: private static final long MILLISECONDS_CONVERSION_MULTIPLIER = 60 * 1000;
27:
28: public static final void configureLogging(
29: boolean doStartupStatsLogging) {
30: String settingsFile = PropertyLoadingFactoryBean
31: .getBaseProperty(KFSConstants.LOG4J_SETTINGS_FILE_KEY);
32: String reloadMinutes = PropertyLoadingFactoryBean
33: .getBaseProperty(KFSConstants.LOG4J_RELOAD_MINUTES_KEY);
34: long reloadMilliseconds = 5 * MILLISECONDS_CONVERSION_MULTIPLIER;
35: try {
36: reloadMilliseconds = Long.parseLong(reloadMinutes)
37: * MILLISECONDS_CONVERSION_MULTIPLIER;
38: } catch (NumberFormatException ignored) {
39: // default to 5 minutes
40: }
41: PropertyConfigurator.configureAndWatch(settingsFile,
42: reloadMilliseconds);
43: printClasspath();
44: }
45:
46: private static void printClasspath() {
47: StringBuffer classpath = new StringBuffer("Classpath is:\n");
48: ClassLoader classloader = Thread.currentThread()
49: .getContextClassLoader();
50: URL[] urls = ((URLClassLoader) classloader).getURLs();
51: for (int i = 0; i < urls.length; i++) {
52: classpath.append(urls[i].getFile()).append("; ");
53: }
54: Logger.getLogger(Log4jConfigurer.class).info(
55: classpath.toString());
56: }
57: }
|