log4j-空的日志文件- [英] log4j - Empty log file -
问题描述
我有一个Java应用程序,它具有以下log4j配置属性,称为log4j-DEV.properties:
I have a Java Application with this following log4j configuration properties, called log4j-DEV.properties:
################################################################
# Root logger option
###############################################################
log4j.rootLogger=ALL, file,stdout
###############################################################
###############################################################
# Logger response
###############################################################
log4j.logger.response=ALL, proxyLog
log4j.additivity.response=false
###############################################################
#############################################################
# APPENDER
#############################################################
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\log\\application.log
log4j.appender.file.Threshold = ALL
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold = ALL
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to a log file
log4j.appender.proxyLog=org.apache.log4j.RollingFileAppender
log4j.appender.proxyLog.Threshold = ALL
log4j.appender.proxyLog.File=C:\\log\\proxyLog.log
log4j.appender.proxyLog.MaxFileSize=10MB
log4j.appender.proxyLog.MaxBackupIndex=1
log4j.appender.proxyLog.layout=org.apache.log4j.PatternLayout
log4j.appender.proxyLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
我将Tomcat用作Application Server,并通过参数 -Dlog4j.configuration ="log4j-DEV.properties"
I use Tomcat as Application Server and I launch it with parameter -Dlog4j.configuration="log4j-DEV.properties"
应用程序启动时,将创建文件 C:\ log \ application.log 和 C:\ log \ proxyLog.log ,但它们为空,尽管应用程序使用说明:
When application starts, the file C:\log\application.log and C:\log\proxyLog.log are created but are empty although application writes log with instruction:
Log log = LogFactory.getLog(getClass());
log.info("Test log");
怎么了?
谢谢
推荐答案
我从以下位置更改了代码:
I changed my code from:
Log log = LogFactory.getLog(getClass());
log.info("Test log");
到
Logger logger = null;
logger = Logger.getRootLogger();
logger.info("TEST");
log4j配置很好,我更改了应用程序的行为以便直接使用log4j类,现在日志正确显示了.
The log4j configuration was fine, I changed the behavior of application in order to use directly log4j classes and now the log appears correctly.
谢谢
这篇关于log4j-空的日志文件-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!