You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "IVolzhev (via GitHub)" <gi...@apache.org> on 2025/12/23 11:57:44 UTC

[I] Unable to log date with milliseconds [logging-log4j2]

IVolzhev opened a new issue, #4010:
URL: https://github.com/apache/logging-log4j2/issues/4010

   ## Description
   
   Unable to log date with milliseconds.
   
   While trying to log error message with 
   
   `PatternLayout "%date{yyyy-MM-dd HH:mm:ss.nnn} %-7level | %m%n"
   `
   got error message:
   
   2025-12-23T11:51:11.882Z Test worker ERROR An exception occurred processing Appender console
   java.time.DateTimeException: Field NanoOfSecond cannot be printed as the value 881000000 exceeds the maximum print width of 3
   
   ## Configuration
   
   **Version:** Log4j 2.25.3
   
   **Operating system:** AlmaLinux 9
   
   **JDK:** openjdk version "1.8.0_452"
   
   ## Logs
   
   ```
   2025-12-23T11:51:11.882Z Test worker ERROR An exception occurred processing Appender console
   java.time.DateTimeException: Field NanoOfSecond cannot be printed as the value 881000000 exceeds the maximum print width of 3
   	at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2559)
   	at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2190)
   	at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746)
   	at org.apache.logging.log4j.core.util.internal.instant.InstantPatternDynamicFormatter$DynamicPatternSequence$1.formatTo(InstantPatternDynamicFormatter.java:624)
   	at org.apache.logging.log4j.core.util.internal.instant.InstantPatternDynamicFormatter$4.formatTo(InstantPatternDynamicFormatter.java:207)
   	at org.apache.logging.log4j.core.util.internal.instant.InstantPatternDynamicFormatter.formatTo(InstantPatternDynamicFormatter.java:89)
   	at org.apache.logging.log4j.core.pattern.DatePatternConverter.format(DatePatternConverter.java:278)
   	at org.apache.logging.log4j.core.pattern.DatePatternConverter.format(DatePatternConverter.java:252)
   	at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:44)
   	at org.apache.logging.log4j.core.layout.PatternLayout$PatternFormatterPatternSerializer.toSerializable(PatternLayout.java:396)
   	at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:251)
   	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:237)
   	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:57)
   	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:227)
   	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:220)
   	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:211)
   	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
   	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:711)
   	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:669)
   	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:645)
   	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:589)
   	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:92)
   	at org.apache.logging.log4j.core.Logger.log(Logger.java:187)
   	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2970)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2922)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2904)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2648)
   	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2587)
   	at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:814)
   	at ru.vasexperts.oima.ctlc.logging.TimestampLoggingTest.testTimestampLogging(TimestampLoggingTest.java:42)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
   	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
   	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
   	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
   	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
   	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
   	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
   	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
   	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
   	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
   	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
   	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
   	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
   	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
   	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
   	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
   	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
   	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
   	at java.util.ArrayList.forEach(ArrayList.java:1259)
   	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
   	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
   	at java.util.ArrayList.forEach(ArrayList.java:1259)
   	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
   	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
   	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
   	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
   	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
   	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
   	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
   	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
   	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
   	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
   	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
   	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
   	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
   	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
   	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
   	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:124)
   	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:99)
   	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:94)
   	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
   	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
   	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
   	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:92)
   	at com.sun.proxy.$Proxy4.stop(Unknown Source)
   	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:200)
   	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:132)
   	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:103)
   	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:63)
   	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
   	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:121)
   	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
   	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
   	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
   ```
   
   ## Reproduction
   
   Unit test:
   
   ```
   package test.logging;
   
   import org.apache.logging.log4j.Level;
   import org.apache.logging.log4j.LogManager;
   import org.apache.logging.log4j.Logger;
   import org.apache.logging.log4j.core.config.Configuration;
   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;
   import org.junit.jupiter.api.Test;
   
   public class TimestampLoggingTest {
       @Test void testTimestampLogging() {
           final ConfigurationBuilder<BuiltConfiguration> configBuilder = ConfigurationBuilderFactory.newConfigurationBuilder();
   
           configBuilder
               .add(
                   configBuilder
                       .newAppender("console", "Console")
                       .add(
                           configBuilder
                               .newLayout("PatternLayout")
                               .addAttribute(
                                   "pattern",
                                   "%date{yyyy-MM-dd HH:mm:ss.nnn} %-7level | %m%n"
                               )
                       )
               )
               .add(
                   configBuilder
                       .newRootLogger()
                       .add(configBuilder.newAppenderRef("console").addAttribute("level", Level.INFO))
               );
   
           final Configuration configuration = configBuilder.build();
   
           org.apache.logging.log4j.core.config.Configurator.reconfigure(configuration);
   
           final Logger logger = LogManager.getLogger(TimestampLoggingTest.class);
   
           logger.error("Some error");
       }
   }
   
   ```


-- 
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: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to log date with milliseconds [logging-log4j2]

Posted by "IVolzhev (via GitHub)" <gi...@apache.org>.
IVolzhev commented on issue #4010:
URL: https://github.com/apache/logging-log4j2/issues/4010#issuecomment-3686393260

   It works on log4j 2.24.3


-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to log date with milliseconds [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #4010:
URL: https://github.com/apache/logging-log4j2/issues/4010#issuecomment-3690086877

   @IVolzhev, thanks so much for the report. Log4j `2.25.0` had a major face lift to its date & time formatting routines — see [the associated release notes](https://logging.apache.org/log4j/2.x/release-notes.html#release-notes-2-25-0-instant-format). All formatting directives are aligned to behave like [DateTimeFormatter](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html). As a result, certain directives (e.g., `n`) started behaving differently. I suggest you to replace your date & time formatting pattern with one of the following instead:
   
   1. `yyyy-MM-dd HH:mm:ss.SSS`
   2. `yyyy-MM-dd HH:mm:ss.n`
   
   I expect this to fix your issue, and hence, I'm closing the issue. If you disagree, please feel free to reach out.


-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to log date with milliseconds [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy closed issue #4010: Unable to log date with milliseconds
URL: https://github.com/apache/logging-log4j2/issues/4010


-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org