[英]log4j RollingFileAppender creates file but leaves it empty
I have a log4j.properties file: 我有一个log4j.properties文件:
log4j.logger.com.mypackage=debug, R, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=myapplication.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
logging into stdout works fine, if I change "debug" in the first line to "error" I get only the error msgs in stdout. 登录到stdout可以正常工作,如果我将第一行中的“ debug”更改为“ error”,我只会在stdout中得到错误消息。
the myapplication.log gets created but it's empty. myapplication.log被创建,但是为空。 If I remove the "R" from the first line, the file will not be created. 如果我从第一行中删除“ R”,则不会创建该文件。
ll shows the file as ll将文件显示为
-rw-r--r-- 1 <myname> staff 0B Oct 28 16:26 myapplication.log
I did a chmod 777 myapplication.log but that didn't help. 我做了一个chmod 777 myapplication.log,但这没有帮助。
I'm on OS X 10.11.1 using STS 3.6.4 我在使用STS 3.6.4的OS X 10.11.1上
I searched google and stackoverflow but couldn't find a solution so far. 我搜索了google和stackoverflow,但到目前为止找不到解决方案。
edit: I changed the line 编辑:我改变了这一行
log4j.logger.com.mypackage=debug, R, stdout
to 至
log4j.rootLogger=debug, R, stdout
Now the messages are written into the file, but only those that are not from mypackage. 现在,消息将被写入文件,但仅写入那些不是来自mypackage的消息。
I changed the file location to 我将文件位置更改为
log4j.appender.R.File=${catalina.home}/logs/myapplication.log
now I get my logging messages written into the file. 现在,我将日志消息写入文件中。
I have no idea why this work but write to myapplication.log (without a path) writes only log messages from other libraries in there. 我不知道为什么要这样做,但写入myapplication.log(不带路径)仅写入来自其他库的日志消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.