You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2016/12/07 00:21:58 UTC
[jira] [Updated] (LOG4J2-1474) CronTriggeringPolicy raise exception
and fail to rollover log file when evaluateOnStartup is true.
[ https://issues.apache.org/jira/browse/LOG4J2-1474?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory updated LOG4J2-1474:
---------------------------------
Summary: CronTriggeringPolicy raise exception and fail to rollover log file when evaluateOnStartup is true. (was: CronTriggeringPolicy raise exception and fail to rollover log file when checkOnStartup is true.)
> CronTriggeringPolicy raise exception and fail to rollover log file when evaluateOnStartup is true.
> --------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-1474
> URL: https://issues.apache.org/jira/browse/LOG4J2-1474
> Project: Log4j 2
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.6.2
> Environment: mac osx capiton/jvm 1.7/log4j-core 2.6.2
> Reporter: yin mingjun
> Fix For: 2.8
>
>
> I am migrating my project from log1.x to log2.x, and I was using DailyRollingFileAppender before, and now I am trying to use RollingFileAppender instead it.
> what i am doing is:
> 1. write a config file, with RollingFile's config, and use CronTriggeringPolicy config log file to roll over at middle-night.
> 2. also set it's CronTriggeringPolicy's evaluateOnStartup=true, require check roll over at start time.
> 3. I touch my log file to an older time, check it is working alright.
> my touch command is:
> {{touch -t 1607220101 biz-pubsvc-service.log}}
> then i start my project, then I got an InvocationTargetException exception...........
> >>>> I then trace into the log4j2's source file, find the exception is caused by CronTriggeringPolicy's initialize method:
> {code}
> public void initialize(RollingFileManager aManager) {
> this.manager = aManager;
> Date nextDate = new Date(this.manager.getFileTime());
> this.nextRollDate = this.cronExpression.getNextValidTimeAfter(nextDate);
> if(this.checkOnStartup && this.nextRollDate.getTime() < System.currentTimeMillis()) {
> this.rollover(); >>> here, call rollover, need this.future
> }
> this.future = this.configuration.getScheduler().scheduleWithCron(this.cronExpression, new CronTriggeringPolicy.CronTrigger()); >>> here assign this.future first time
> }
> {code}
> we also refer CronTriggeringPolicy's rollover method's code:
> {code}
> private void rollover() {
> this.manager.getPatternProcessor().setPrevFileTime(this.nextRollDate.getTime());
> this.manager.rollover();
> Date fireDate = this.future.getFireTime(); >>> raise null pointer exception here !!!
> Calendar cal = Calendar.getInstance();
> cal.setTime(fireDate);
> cal.add(13, -1);
> this.nextRollDate = cal.getTime();
> }
> {code}
> I think this BUG is easy to fix up by moving [ this.future = ...] 's assignment just before the call of [ this.rollover(); ].
> thanks.
> Yin Mingjun
> PS1: my log4j2.xml config file -------------------------------------------------------
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="warn">
> <appenders>
> <RollingFile name="myFile" fileName="biz-pubsvc-service.log" filePattern="biz-pubsvc-service.log.%d{yyyy-MM-dd}" append="true">
> <PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss,SSS}] %-5p [%t] %c{2} - %m%n"/>
> <CronTriggeringPolicy schedule="0 0 0 * * ?" evaluateOnStartup="true"/>
> </RollingFile>
> <Console name="myConsole" target="SYSTEM_OUT">
> <PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss,SSS}] %-5p [%t] %c{2} - %m%n"/>
> </Console>
> </appenders>
> <loggers>
> <root level="trace">
> <appender-ref ref="myConsole"/>
> <appender-ref ref="myFile"/>
> </root>
> </loggers>
> </configuration>
> {code}
> PS2: the raising exception's call stack ----------------------------------------
> {code}
> 2016-07-25 18:30:25,910 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile. java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:132)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:918)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:858)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:850)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:479)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:219)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:231)
> at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:496)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:566)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:582)
> at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:217)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org