如何在log4j配置中包含日期

时间:2013-07-18 22:04:01

标签: java properties log4j

这是我在服务器中看到的当前日志记录:

12:40:10,190 | INFO  | -549263035-19951 | ServiceImpl    | Upload started
12:40:12,912 | INFO  | -549263035-19960 | ServiceImpl    | Upload started
12:40:12,915 | INFO  | -549263035-19958 | ServiceImpl    | Upload started

My application is using log4j to implement logging. here is the log4j.properties file which is sitting inside META-INF. 

log4j.rootCategory=DEBUG, O
log4j.appender.O=org.apache.log4j.ConsoleAppender
log4j.appender.O.layout=org.apache.log4j.PatternLayout
log4j.appender.O.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n


As we can clearly see, current logging has the time information for every event. I wanted to know if there is a way I could make some changes in this properties file or elsewhere to include the full timestamp i.e. Date and time both.
像这样的东西: 2013-07-18 12:40:12 |信息| -549263035-19958 | ServiceImpl |上传已开始

Thanks for suggestion.

1 个答案:

答案 0 :(得分:0)

找到我的答案。 此应用程序部署在Servicemix容器中。显然在servicemix的安装目录中,我找到了这个配置文件。 “/usr/local/servicemix/etc/org.ops4j.pax.logging.cfg”。

在这个文件中,有一个SiftingAppender使用%d [ABSOLUTE]作为转换模式。所以基本上在servicemix下部署的每个bundle都将使用这个“siftingappender”属性。我刚从此配置文件中删除了[ABSOLUTE]并开始在我的日志中获取日期。