According to this log4j2 configuration I am trying to set the "log4j2.component.properties" file in my NetBeans project. I have already configured my log4j2 with ASYNC_LOGGERS and one thing I particularly need is the "log4j.Clock" property. Because I get the data at a very high speed from the Servers and we expect that the logging timestamp needs to be perfect. How can I use the "log4j2.component.properties" file in my project. Currently I created the "log4j2.component.properties" file in my default package of the project and set the values as below:
My log4j2.component.properties file
Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
AsyncLogger.RingBufferSize=512*1024
-DAsyncLoggerConfig.RingBufferSize=512*1024
log4j.Clock=SystemClock
My log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<RollingRandomAccessFile name="Messages-log" fileName="Log4J/Messages-${date:yyyy-MM-dd}.log"
immediateflush="true" filePattern="Log4J/Messages-%d{MM-dd-yyyy-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="Error-log" fileName="Log4J/Errors-${date:yyyy-MM-dd}.log"
immediateflush="false" filePattern="Log4J/Errors-%d{MM-dd-yyyy-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Logger name="Messages-log" level="info" additivity="false">
<appender-ref ref="Messages-log" level="info"/>
</Logger>
<Logger name="Error-log" level="info" additivity="false">
<appender-ref ref="Error-log" level="info"/>
</Logger>
<root level="info">
<appender-ref ref="Messages-log"/>
<appender-ref ref="Error-log"/>
</root>
</Loggers>
</Configuration>
Is this correct way of using it? I am highly confused in how to use it. I want the timestamp to be perfect and so I want to use the "log4j2.clock" parameter set to "org.apache.logging.log4j.core.util.Clock". All I want is asynchronous logging with the exact time when the record has reached. But I am getting the following exception:
ERROR StatusLogger Could not create org.apache.logging.log4j.core.util.Clock: java.lang.InstantiationException: org.apache.logging.log4j.core.util.Clock, using default SystemClock for timestamps.
Please help me.
Thanks in advance