Apache Log4j使用特定时区进行日志记录 [英] Apache Log4j Logging with specific timezone

查看:775
本文介绍了Apache Log4j使用特定时区进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望日志应包含特定时区的日期条目。有没有办法强制时区在 log4j.properties

I want the log should contain date entries of specific timezone. Is there any way of forcing timezone in log4j.properties?

现在我正在使用JDK 1.5,因为你已经知道在JDK 1.5中删除了JDK 1.5中的时区错误。对于JDK 1.5,默认情况下显示GMT时区。我想在Log4j中配置我的特定时区。

Now I am using JDK 1.5, As you already know that there is timezone bug in JDK 1.5 that is removed in JDK 1.5. In case of JDK 1.5 it by default shows "GMT" timezone. I want to configure in Log4j my specific timezone.

推荐答案

这将允许您在日志的每一行中查看时区信息:

This will allow you to see timezone information in each line of your logs:

%d{yyyy-MM-dd/HH:mm:ss.SSS/zzz}

诀窍是在模式中包含'zzz',因为根据Javadoc for java.text.SimpleDateFormat( http://docs.oracle.com/javase/1.4.2/docs/api/java/ text / SimpleDateFormat.html ),这是时区的代码。 Log4J使用与SimpleDateFormat相同的规则。

The trick is to include 'zzz' in the pattern since according to Javadoc for java.text.SimpleDateFormat ( http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html ), that's the code for timezone. Log4J uses the same rules as SimpleDateFormat.

Log4J Javadoc中有更多详细信息:

There are more details over the in the Log4J Javadoc:

< a href =http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html> http://logging.apache.org/log4j/1.2/apidocs/org/apache /log4j/PatternLayout.html

查找表格中转换字符为字母d的行。

Look for the row in the table where the 'Conversion Character' is the letter 'd'.

这篇关于Apache Log4j使用特定时区进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆