[ 
https://issues.apache.org/jira/browse/LOG4J2-1964?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16116003#comment-16116003
 ] 

Leliel Trethowen commented on LOG4J2-1964:
------------------------------------------

Not fixed per latest snapshot at: 
https://repository.apache.org/content/groups/snapshots/org/apache/logging/log4j/log4j-core/2.9-SNAPSHOT/
log4j-core-2.9-20170730.210717-98.jar

Minimal example inline
{code}
package leliel;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import 
org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;

public class Main {

    public static void main(String[] args) {
            //initial config with indexed rollover
        ConfigurationBuilder<BuiltConfiguration> builder = 
ConfigurationBuilderFactory.newConfigurationBuilder();
        builder.setConfigurationName("LOG4j2-1964 demo");
        builder.setStatusLevel(Level.ERROR);
        builder.add(builder.newAppender("consoleLog", "Console")
            .addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR));
        builder.add(builder.newAppender("fooAppender", "RollingFile")
                .addAttribute("fileName", "foo.log")
                .addAttribute("filePattern", "foo.log.%i")
                .addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
                        .addAttribute("size", "10MB")));
        builder.add(builder.newRootLogger(Level.INFO)
                .add(builder.newAppenderRef("consoleLog"))
                .add(builder.newAppenderRef("fooAppender")));

        Configurator.initialize(builder.build());
        LogManager.getLogger("root").info("just to show it works.");

        //rebuild config with date based rollover
        builder = ConfigurationBuilderFactory.newConfigurationBuilder();
        builder.setConfigurationName("LOG4j2-1964 demo");
        builder.setStatusLevel(Level.ERROR);
        builder.add(builder.newAppender("consoleLog", "Console")
                .addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR));
        builder.add(builder.newAppender("fooAppender", "RollingFile")
                .addAttribute("fileName", "foo.log")
                .addAttribute("filePattern", "foo.log.%i")
                .addComponent(builder.newComponent("TimeBasedTriggeringPolicy")
                        .addAttribute("interval", 5)
                        .addAttribute("modulate", true)));
        builder.add(builder.newRootLogger(Level.INFO)
                .add(builder.newAppenderRef("consoleLog"))
                .add(builder.newAppenderRef("fooAppender")));

        Configurator.initialize(builder.build());
    }
}
{code}

{noformat}/usr/local/java/jdk1.7.0_79/bin/java -Didea.launcher.port=7535 
-Didea.launcher.bin.path=/home/user/leliel/.local/idea-IC-163.12024.16/bin 
-Dfile.encoding=UTF-8 -classpath 
/usr/local/java/jdk1.7.0_79/jre/lib/charsets.jar:/usr/local/java/jdk1.7.0_79/jre/lib/deploy.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/dnsns.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/localedata.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunec.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunjce_provider.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunpkcs11.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/zipfs.jar:/usr/local/java/jdk1.7.0_79/jre/lib/javaws.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jce.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jfr.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jfxrt.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jsse.jar:/usr/local/java/jdk1.7.0_79/jre/lib/management-agent.jar:/usr/local/java/jdk1.7.0_79/jre/lib/plugin.jar:/usr/local/java/jdk1.7.0_79/jre/lib/resources.jar:/usr/local/java/jdk1.7.0_79/jre/lib/rt.jar:/home/user/leliel/git/github/Log4j2-testing/out/production/Log4j2-testing:/home/user/leliel/Downloads/log4j-api-2.9-20170730.210648-97.jar:/home/user/leliel/Downloads/log4j-core-2.9-20170730.210717-98.jar:/home/user/leliel/.local/idea-IC-163.12024.16/lib/idea_rt.jar
 com.intellij.rt.execution.application.AppMain leliel.Main
just to show it works.
2017-08-07 13:40:51,316 main ERROR Could not create plugin of type class 
org.apache.logging.log4j.core.appender.RollingFileAppender for element 
RollingFile: java.lang.IllegalStateException: Pattern does not contain a date 
java.lang.IllegalStateException: Pattern does not contain a date
        at 
org.apache.logging.log4j.core.appender.rolling.PatternProcessor.getNextTime(PatternProcessor.java:142)
        at 
org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy.initialize(TimeBasedTriggeringPolicy.java:113)
        at 
org.apache.logging.log4j.core.appender.rolling.RollingFileManager.setTriggeringPolicy(RollingFileManager.java:331)
        at 
org.apache.logging.log4j.core.appender.rolling.RollingFileManager.updateData(RollingFileManager.java:596)
        at 
org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:120)
        at 
org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:115)
        at 
org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:183)
        at 
org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:144)
        at 
org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
        at 
org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:204)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:57)
        at leliel.Main.main(Main.java:48)
        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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

2017-08-07 13:40:51,320 main ERROR Unable to invoke factory method in class 
org.apache.logging.log4j.core.appender.RollingFileAppender for element 
RollingFile: java.lang.IllegalStateException: No factory method found for class 
org.apache.logging.log4j.core.appender.RollingFileAppender 
java.lang.IllegalStateException: No factory method found for class 
org.apache.logging.log4j.core.appender.RollingFileAppender
        at 
org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:229)
        at 
org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:204)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)
        at 
org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:57)
        at leliel.Main.main(Main.java:48)
        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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

2017-08-07 13:40:51,321 main ERROR Null object returned for RollingFile in 
Appenders.
2017-08-07 13:40:51,322 main ERROR Unable to locate appender "fooAppender" for 
logger config "root"

Process finished with exit code 0
{noformat}

Fix is pretty trivial, Set the patternProcessor first, not last.
{code}
    @Override
    public void updateData(final Object data) {
        final FactoryData factoryData = (FactoryData) data;
        setPatternProcessor(new PatternProcessor(factoryData.getPattern(), 
getPatternProcessor()));
        setRolloverStrategy(factoryData.getRolloverStrategy());
        setTriggeringPolicy(factoryData.getTriggeringPolicy());
    }
{code}

> Dynamic reconfiguration does not work for filePattern of RollingFile
> --------------------------------------------------------------------
>
>                 Key: LOG4J2-1964
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1964
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.2
>         Environment: JDK 1.7.80
>            Reporter: Xiaoshuang LU
>             Fix For: 2.9
>
>
> The initial log4j2.xml file was
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="INFO" monitorInterval="60">
>     <Properties>
>         <Property name="LOG_HOME">./logs</Property>
>     </Properties>
>     <Appenders>
>         <RollingFile
>             name="RollingFileAppender"
>             fileName="${LOG_HOME}/log.log"
>             filePattern="${LOG_HOME}/log.log.%d{yyyy-MM-dd}.%i">
>             <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
>             <PatternLayout pattern="%d{DEFAULT} %p %t %c %L: %m%n"/>
>             <Policies>
>                 <OnStartupTriggeringPolicy/>
>                 <!--<TimeBasedTriggeringPolicy/>-->
>                 <SizeBasedTriggeringPolicy size="256MB"/>
>             </Policies>
>             <DefaultRolloverStrategy max="8"/>
>         </RollingFile>
>     </Appenders>
>     <Loggers>
>         <Root level="INFO">
>             <AppenderRef ref="RollingFileAppender"/>
>         </Root>
>     </Loggers>
> </Configuration>
> {code}
> And then I changed filePattern to
> {code}
> filePattern="${LOG_HOME}/log.log.%i"
> {code}
> Log file names still contain date.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to