我在应该显示班级名称和行号的地方出现问号。
这是我的log4j.properties
文件
logfile=C:/Softwares/logFiles
log4j.rootLogger=ERROR, generalDebug, generalError
log4j.appender.generalDebug=org.apache.log4j.RollingFileAppender
log4j.appender.generalDebug.File=${logfile}/debug.log
log4j.appender.generalDebug.MaxFileSize=10MB
log4j.appender.generalDebug.MaxBackupIndex=10
log4j.appender.generalDebug.layout=org.apache.log4j.PatternLayout
log4j.appender.generalDebug.layout.ConversionPattern=[%-5p] %d{ISO8601}|%r %C|%L|%x - %m%n
log4j.appender.generalDebug.Threshold=DEBUG
log4j.appender.generalError=org.apache.log4j.RollingFileAppender
log4j.appender.generalError.File=${logfile}/error.log
log4j.appender.generalError.MaxFileSize=10MB
log4j.appender.generalError.MaxBackupIndex=10
log4j.appender.generalError.layout=org.apache.log4j.PatternLayout
log4j.appender.generalError.layout.ConversionPattern=[%-5p] %d{ISO8601}|%r %C|%L|%x - %m%n
log4j.appender.generalError.Threshold=ERROR
#######################################################################
log4j.logger.Logging=DEBUG, HipDebug, HipError
log4j.additivity.Logging=false
log4j.appender.HipDebug=org.apache.log4j.RollingFileAppender
log4j.appender.HipDebug.File=${logfile}/HipDebug.log
log4j.appender.HipDebug.MaxFileSize=10MB
log4j.appender.HipDebug.MaxBackupIndex=10
log4j.appender.HipDebug.layout=org.apache.log4j.PatternLayout
log4j.appender.HipDebug.layout.ConversionPattern=[%-5p] %d{ISO8601}|%r %C|%L|%x - %m%n
log4j.appender.HipDebug.Threshold=DEBUG
log4j.appender.HipError=org.apache.log4j.RollingFileAppender
log4j.appender.HipError.File=${logfile}/HipError.log
log4j.appender.HipError.MaxFileSize=10MB
log4j.appender.HipError.MaxBackupIndex=10
log4j.appender.HipError.layout=org.apache.log4j.PatternLayout
log4j.appender.HipError.layout.ConversionPattern=[%-5p] %d{ISO8601}|%r %C|%L|%x - %m%n
log4j.appender.HipError.Threshold=ERROR
日志同时处于DEBUG和ERROR级别。
[ERROR] 2019-04-11 22:40:30,975|0 ?|?| - I'm Writing
[DEBUG] 2019-04-11 22:40:30,975|0 ?|?| - I'm Writing
这是我的代码:
PropertyConfigurator.configure("C:\\Softwares\\ConfigFiles\\log4j.properties");
Logger logger = Logger.getLogger(Logeverything.class);
logger.log(Logeverything.class.getCanonicalName(), Level.ERROR, "I'm Writing", null);
有人可以告诉我这是怎么回事吗?
谢谢
答案 0 :(得分:0)
使用logger.error("I'm Writing");
代替logger.log(Logeverything.class.getCanonicalName(), Level.ERROR, "I'm Writing", null);
Logeverything.java
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Logeverything {
static {
PropertyConfigurator.configure("src/main/resources/ConfigFiles/log4j.properties");
}
private static Logger logger = Logger.getLogger(Logeverything.class);
public static void main(String[] args) {
logger.error("I'm Writing");
}
}
$ cat error.log
[ERROR] 2019-04-11 10:56:16,302|0 Logeverything|14| - I'm Writing