The Log4j log output time is 8 hours less than the system time.

Source: Internet
Author: User

The Log4j log output time is 8 hours less than the system time.

1. First problem: 8 hours earlier

The log output by Log4j is eight hours earlier than the system time, but the log output by the eclipse console is correct.

Log4j configuration is as follows:

#all logger output level is 'ERROR' and output position is stdout#so only write our project's DEBUG log and ERROR log of the otherslog4j.rootLogger=ERROR, stdout, R#log4j.appender is set output postion#log4j.logger is set some package(some package your want output logger specially)=[output level],[...output position]#log4j.logger.org.springframework=OFF  #log4j.logger.org.apache.commons=OFF #log4j.logger.org.apache.struts=OFF   #log4j.logger.org.hibernate=OFF#log4j.logger.org.logicalcobwebs=OFF#only write our project's log(DEBUG)log4j.logger.com.diantu=DEBUGlog4j.logger.org.logicalcobwebs.proxool=DEBUG, proxool#in the consolelog4j.appender.stdout=org.apache.log4j.ConsoleAppender#config stdout position output contain INFO level and uplog4j.appender.stdout.Threshold=DEBUGlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%-5p] %l:%t - %m %n#in the daily fileslog4j.appender.R=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.R.Threshold=DEBUGlog4j.appender.R.File=${root.path}/log/EMR.loglog4j.appender.R.DatePattern='.'yyyy-MM-dd'.log'log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d [%-5p] %l:%t - %m %nlog4j.logger.com.statestr=DEBUGlog4j.appender.proxool=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.proxool.Threshold=DEBUGlog4j.appender.proxool.File=${root.path}/log/proxool.loglog4j.appender.proxool.DatePattern='.'yyyy-MM-dd'.log'log4j.appender.proxool.layout=org.apache.log4j.PatternLayout log4j.appender.proxool.layout.ConversionPattern=%d [%-5p] %l:%t - %m %n

There was a blog about the problem: http://peng4602.iteye.com/blog/1844356.

However, this method does not work.

 

Cause analysis: the time output by eclipse is correct, so the JVM time zone settings should be correct. The system time is correct, so the system time zone should be correct.

The problem may be that tomcat fails to obtain the time zone, so the default time zone is used. Therefore, the Beijing time difference is 8 hours. solution,

Find catalina. bat under C: \ apache-tomcat-8.0.33 \ bin to open the Editor:

In

set _EXECJAVA=%_RUNJAVA%set MAINCLASS=org.apache.catalina.startup.Bootstrapset ACTION=startset SECURITY_POLICY_FILE=set DEBUG_OPTS=set JPDA=

Add:

Set-Duser. timezone = GMT + 08

Save and restart tomcat.

Solution: set JAVA_OPTS = % JAVA_OPTS %-Xms256m-Xmx800m-Duser. timezone = GMT + 08

Tomcat-8.0.33 does not work.

 

2. Second problem: Repeated log4j log file output

2016-04-22 01:51:28,427 [DEBUG] org.logicalcobwebs.proxool.HouseKeeper.sweep(HouseKeeper.java:81):HouseKeeper - 000036 (00/05/01) - Testing connection 2: True 2016-04-22 01:51:28,427 [DEBUG] org.logicalcobwebs.proxool.HouseKeeper.sweep(HouseKeeper.java:81):HouseKeeper - 000036 (00/05/01) - Testing connection 2: True 

The problem is that the log4j configuration file has been added to a file twice.

First time:

Log4j. rootLogger = ERROR, stdout, R, proxool

 

Including proxool

 

Second:

Log4j.logger.org. logicalcobwebs. proxool = DEBUG, proxool

 

So of course it will be repeated twice.

Remove proxool from log4j. rootLogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.