Volkan Yazici created LOG4J2-3183:
-------------------------------------

             Summary: JsonTemplateLayout epoch resolver renders incorrect values
                 Key: LOG4J2-3183
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3183
             Project: Log4j 2
          Issue Type: Bug
          Components: JsonTemplateLayout
    Affects Versions: 2.14.1, 2.14.0
            Reporter: Volkan Yazici
            Assignee: Volkan Yazici
             Fix For: 2.15.0


JTL epoch resolver renders the same timestamp repeatedly. See the following 
application using {{log4j-layout-template-json}} 2.14.1:

{code:java}
public static void main(String[] args) throws InterruptedException {
    initLog4j();
    Logger logger = LogManager.getLogger();
    for (int i = 0; i < 5; i++) {
        logger.info("{}", i);
        Thread.sleep(100);
    }
}

private static LoggerContext initLog4j() {

    // Create the configuration builder.
    ConfigurationBuilder<BuiltConfiguration> configBuilder = 
ConfigurationBuilderFactory
            .newConfigurationBuilder()
            .setStatusLevel(Level.ERROR)
            .setConfigurationName(TimeDriftDemo.class.getSimpleName());

    // Create the configuration.
    String appenderName = "Console";
    String eventTemplate = "" +
            "[{\"$resolver\":\"timestamp\",\"epoch\":{\"unit\":\"nanos\"}}" +
            
",{\"$resolver\":\"timestamp\",\"pattern\":{\"format\":\"ss.SSS'Z'\",\"timeZone\":\"UTC\",\"locale\":\"en_US\"}}"
 +
            "]";
    Configuration config = configBuilder
            .add(configBuilder
                    .newAppender(appenderName, "Console")
                    .add(configBuilder
                            .newLayout("JsonTemplateLayout")
                            .addAttribute(
                                    "eventTemplate",
                                    eventTemplate)))
            .add(configBuilder.newLogger("com.vlkan", Level.TRACE))
            .add(configBuilder
                    .newRootLogger(Level.ERROR)
                    .add(configBuilder.newAppenderRef(appenderName)))
            .build(false);

    // Initialize the configuration.
    return Configurator.initialize(config);

}
{code}

Note the identical epochs in the output:

{code:json}
[1635411617932465000,"17.932Z"]
[1635411617932465000,"18.034Z"]
[1635411617932465000,"18.134Z"]
[1635411617932465000,"18.234Z"]
[1635411617932465000,"18.335Z"]
{code}

The issue was originally reported by Andrew Harris in [a log4j-user 
post|https://lists.apache.org/thread.html/re7498afa43c9cb91391b0798c1f7bbf4ea97111af1130ebeb155b824%40%3Clog4j-user.logging.apache.org%3E].



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to