Apache Log4j Logging with specific timezone

后端 未结 6 1984
半阙折子戏
半阙折子戏 2021-02-19 07:32

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

Now I am using JDK 1.5, As you al

6条回答
  •  野的像风
    2021-02-19 08:09

    Include a date argument in your ConversionPattern. From the PatternLayout documentation:

    date -

    Used to output the date of the logging event in the local time zone. To output the date in universal time use the %utcdate pattern. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %date{HH:mm:ss,fff} or %date{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter).

    The date format specifier admits the same syntax as the time pattern string of the ToString.

    For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatter, DateTimeDateFormatter and respectively Iso8601DateFormatter. For example, %date{ISO8601} or %date{ABSOLUTE}.

    These dedicated date formatters perform significantly better than ToString.

提交回复
热议问题