Apache Log4j Logging with specific timezone

后端 未结 6 1987
半阙折子戏
半阙折子戏 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:08

    There are three steps to this:

    1) Add the log4j-extras dependency here

    2) Set the layout to EnhancedPatternLayout: log4j.appender.stdout.layout=org.apache.log4j.EnhancedPatternLayout (change stdout to whatever appender you are using)

    3) Add your timezone in braces after your date time pattern log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}{IST} %-5p %c{1}:%L - %m%n (Here IST in my case)

    You can refer to list of timezone ID's available in java here or here

提交回复
热议问题