You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2021/10/28 11:50:00 UTC

[jira] [Commented] (LOG4J2-3183) JsonTemplateLayout epoch resolver renders incorrect values

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

ASF subversion and git services commented on LOG4J2-3183:
---------------------------------------------------------

Commit 2dd7063fb6c6fe73070aded6607a2e2d53613b46 in logging-log4j2's branch refs/heads/release-2.x from Volkan Yazici
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=2dd7063 ]

LOG4J2-3183 Avoid using MutableInstant of the event as a cache key in JsonTemplateLayout.


> 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.0, 2.14.1
>            Reporter: Volkan Yazici
>            Assignee: Volkan Yazici
>            Priority: Major
>             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)