Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 919ED200BBB for ; Thu, 6 Oct 2016 07:27:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 905FC160AEA; Thu, 6 Oct 2016 05:27:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D8977160ADE for ; Thu, 6 Oct 2016 07:27:22 +0200 (CEST) Received: (qmail 86564 invoked by uid 500); 6 Oct 2016 05:27:21 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 85528 invoked by uid 99); 6 Oct 2016 05:27:21 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Oct 2016 05:27:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id D301E2C2A6A for ; Thu, 6 Oct 2016 05:27:20 +0000 (UTC) Date: Thu, 6 Oct 2016 05:27:20 +0000 (UTC) From: "Remko Popma (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (LOG4J2-1474) CronTriggeringPolicy raise exception and fail to rollover log file when checkOnStartup is true. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 06 Oct 2016 05:27:23 -0000 [ https://issues.apache.org/jira/browse/LOG4J2-1474?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Remko Popma updated LOG4J2-1474: -------------------------------- Fix Version/s: (was: 2.7) 2.8 > CronTriggeringPolicy raise exception and fail to rollover log file when checkOnStartup 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} > > > > > > > > > > > > > > > > > > > {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