package net.meybo.mail;
import org.apache.log4j.Logger;
public class Log4jTest {
private static final Logger logger = (Logger) Logger.getLogger(Log4jTest.class.getName());
public static void main(String[] args) {
try {
String str = "3d";
logger.debug("str length:"+str.length());
int num = Integer.parseInt(str);
p(new Integer(num));
} catch (NumberFormatException e) {
logger.warn("字符串格式化错误!"+e);
logger.error("字符串格式化错误! error级别的!!!"+e.getMessage());
logger.info("系统初始化!");
}
}
public static void p(Object obj){
System.out.println(obj);
}
}
log4j.properties
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c{1}.%M(%L) | %m%n
log4j.appender.stdout.MaxFileSize=30MB
log4j.appender.stdout.MaxBackupIndex=1
log4j.appender.stdout.file=E:\\output.log
Log4j配置[输出到文件]
最新推荐文章于 2024-03-10 09:29:50 发布