001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.sys.context; 017 018 import java.net.URL; 019 import java.net.URLClassLoader; 020 021 import org.apache.log4j.Logger; 022 import org.apache.log4j.PropertyConfigurator; 023 import org.kuali.kfs.sys.KFSConstants; 024 025 public class Log4jConfigurer { 026 private static final long MILLISECONDS_CONVERSION_MULTIPLIER = 60 * 1000; 027 028 public static final void configureLogging(boolean doStartupStatsLogging) { 029 String settingsFile = PropertyLoadingFactoryBean.getBaseProperty(KFSConstants.LOG4J_SETTINGS_FILE_KEY); 030 String reloadMinutes = PropertyLoadingFactoryBean.getBaseProperty(KFSConstants.LOG4J_RELOAD_MINUTES_KEY); 031 long reloadMilliseconds = 5 * MILLISECONDS_CONVERSION_MULTIPLIER; 032 try { 033 reloadMilliseconds = Long.parseLong(reloadMinutes) * MILLISECONDS_CONVERSION_MULTIPLIER; 034 } 035 catch (NumberFormatException ignored) { 036 // default to 5 minutes 037 } 038 PropertyConfigurator.configureAndWatch(settingsFile, reloadMilliseconds); 039 printClasspath(); 040 } 041 042 private static void printClasspath() { 043 StringBuffer classpath = new StringBuffer("Classpath is:\n"); 044 ClassLoader classloader = Thread.currentThread().getContextClassLoader(); 045 URL[] urls = ((URLClassLoader) classloader).getURLs(); 046 for (int i = 0; i < urls.length; i++) { 047 classpath.append(urls[i].getFile()).append("; "); 048 } 049 Logger.getLogger(Log4jConfigurer.class).info(classpath.toString()); 050 } 051 }