ramanathan1504 opened a new issue, #4489:
URL: https://github.com/apache/logging-log4j2/issues/4489
With the thread-local cache turned on (`log4j2.enableThreadlocals`, the
default), `PatternLayout` `%d{...}` and JsonTemplateLayout's `timestamp`
resolver print an empty string for an event at 1969-12-31T23:59:59.999Z when
the pattern has millisecond precision, and for any event in that second when
the pattern is coarser. This repeats for every such event on the thread until
an event with a different instant is formatted, and it happens again on each
new thread. With `-Dlog4j2.enableThreadlocals=false` or
`-Dlog4j2.instantFormatter=legacy`, the same events format correctly.
## Configuration
**Version:** 2.25.0, 2.26.1, 2.x at `ea28f5a78b`, 3.0.0-beta3, main at
`2bb673f650`
**Operating system:** macOS
**JDK:** OpenJDK 17.0.14
## Logs
2.26.1, each layout formatting events on a fresh thread:
```
FAIL | %d{HH:mm:ss.SSS}{UTC}, events -1,-1,0,-1 ms |
expected=23:59:59.999,23:59:59.999,00:00:00.000,23:59:59.999 |
observed=<empty>,<empty>,00:00:00.000,00:00:00.00/
FAIL | %d{DEFAULT}{UTC}, -1 ms | expected=1969-12-31 23:59:59,999 |
observed=<empty>
FAIL | %d{HH:mm:ss}{UTC}, events -1000,-1000,0,-1000 ms |
expected=23:59:59,23:59:59,00:00:00,23:59:59 |
observed=<empty>,<empty>,00:00:00,00:00:0/
FAIL | %d{yyyy-MM-dd HH:mm}{UTC}, -1000 ms | expected=1969-12-31 23:59 |
observed=<empty>
FAIL | JsonTemplateLayout timestamp HH:mm:ss.SSS UTC, -1 ms |
expected={"t":"23:59:59.999"} | observed={"t":""}
FAIL | custom clock returning -1,-1,0,-1 ms, Logger.info to File
%d{HH:mm:ss.SSS}{UTC}|%m | observed=|a,|b,00:00:00.000|c,00:00:00.00/|d
PASS | %d{UNIX_MILLIS}, -1 ms | observed=-1
```
2.x at `ea28f5a78b`:
```
FAIL | %d{HH:mm:ss.SSS}{UTC}, events -1,-1,0,-1 ms |
observed=<empty>,<empty>,00:00:00.000,23:59:59.999
FAIL | %d{HH:mm:ss}{UTC}, -500 ms | expected=23:59:59 | observed=<empty>
```
The `00:00:00.00/` values on 2.26.1 are a separate pre-epoch arithmetic
problem, fixed on 2.x by #4400.
## Reproduction
```xml
<Configuration status="WARN">
<Appenders>
<Console name="MS"><PatternLayout
pattern="%d{HH:mm:ss.SSS}{UTC}"/></Console>
</Appenders>
<Loggers><Root level="OFF"/></Loggers>
</Configuration>
```
```java
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Appender app = ctx.getConfiguration().getAppender("MS");
LogEvent event = Log4jLogEvent.newBuilder()
.setLoggerName("repro").setLevel(Level.INFO)
.setMessage(new SimpleMessage("m"))
.setTimeMillis(-1)
.build();
Thread t = new Thread(() -> System.out.println(
"[" + new String(app.getLayout().toByteArray(event),
StandardCharsets.UTF_8) + "]"));
t.start();
t.join();
```
Expected `[23:59:59.999]`; prints `[]`. With `%d{HH:mm:ss}{UTC}` and
`setTimeMillis(-1000)` it also prints `[]`. The same result comes from a
`log4j2.clock` implementation returning `-1` and a normal `logger.info(...)`
call to a `File` appender.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]