1 31 32 package org.opencms.main; 33 34 import org.opencms.configuration.CmsConfigurationManager; 35 import org.opencms.file.CmsResource; 36 import org.opencms.util.CmsFileUtil; 37 38 import java.io.File ; 39 import java.net.URL ; 40 41 import org.apache.commons.collections.ExtendedProperties; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 import org.apache.log4j.PropertyConfigurator; 45 import org.apache.log4j.helpers.Loader; 46 47 67 public final class CmsLog { 68 69 70 public static final String FILE_LOG = "opencms.log"; 71 72 73 public static final String FOLDER_LOGS = "logs" + File.separatorChar; 74 75 76 public static final Log INIT = LogFactory.getLog("org.opencms.init"); 77 78 79 private static String m_logFileRfsPath; 80 81 84 private CmsLog() { 85 86 } 88 89 92 static { 93 try { 94 URL url = Loader.getResource("log4j.properties"); 96 if (url != null) { 97 String path = CmsFileUtil.normalizePath(url, '/'); 99 String webInfPath = CmsResource.getParentFolder(CmsResource.getFolderPath(path)); 101 String configFilePath = webInfPath 103 + CmsSystemInfo.FOLDER_CONFIG 104 + CmsConfigurationManager.DEFAULT_XML_FILE_NAME; 105 File configFile = new File (configFilePath); 106 if (configFile.exists()) { 107 ExtendedProperties configuration = new ExtendedProperties(path); 109 boolean setLogFile = configuration.getBoolean("opencms.set.logfile", false); 111 if (setLogFile) { 112 String logFilePath = CmsFileUtil.normalizePath(webInfPath + FOLDER_LOGS + FILE_LOG, '/'); 114 File logFile = new File (logFilePath); 115 m_logFileRfsPath = logFile.getAbsolutePath(); 116 System.setProperty("opencms.logfile", m_logFileRfsPath); 117 PropertyConfigurator.configure(path); 119 } 120 } 121 INIT.info(". Log4j config file : " + path); 123 } 124 } catch (SecurityException e) { 125 } catch (Exception e) { 127 e.printStackTrace(System.err); 129 } 130 } 131 132 142 public static Log getLog(Object obj) { 143 144 if (obj instanceof String ) { 145 return LogFactory.getLog((String )obj); 146 } else if (obj instanceof Class ) { 147 return LogFactory.getLog((Class )obj); 148 } else { 149 return LogFactory.getLog(obj.getClass()); 150 } 151 } 152 153 161 protected static String getLogFileRfsPath() { 162 163 return m_logFileRfsPath; 164 } 165 } | Popular Tags |