📄 logutil.java
字号:
package com.xuntian.material.util;
import java.io.File;
import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
* @author lip
* Mar 6, 2006
* copyright@xuntian
*/
public class LogUtil {
/**
* the file path
*/
private static final String logCofigFile=Constants.LOG_CONFIG_FILE;
private static ResourceBundle myResource=null;
static {
/**
* load the configuration property file.
*/
try {
myResource =ResourceBundle.getBundle(logCofigFile);
/**
* change the path of the log file.
*/
Properties logProperties = new Properties();
String tempKey = "";
for (Enumeration e = myResource.getKeys(); e.hasMoreElements(); ) {
tempKey = (String) e.nextElement();
logProperties.put(tempKey, myResource.getString(tempKey));
}
/**
* configure the loggers.
*/
String LOG_PATH = logProperties.getProperty("log4j.appender.AppAppender.File");
File logFile = new File(LOG_PATH);
logFile.getParentFile().mkdirs();
PropertyConfigurator.configure(logProperties);
} catch (MissingResourceException mre) {
mre.printStackTrace();
}
}
/**
* Return a log utility for class denoted by <code>className</code>
* @param className name of class which the logger belongs to.
*/
protected static Logger getLogger(String className) {
Logger cat = Logger.getLogger(className);
return cat;
}
/**
* Return a log utility for class denoted by <code>a_Class</code>
* @param a_Class class which the logger belongs to.
*/
public static Logger getLogger(Class a_Class) {
return getLogger(a_Class.getName());
}
/**
* Return a log utility for class denoted by <code>a_Object</code>
* @param a_Object object which the logger belongs to.
*/
public static Logger getLogger(Object a_Object) {
return getLogger(a_Object.getClass().getName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -