Reputation: 201
I have migrated from log4j 1.2.17 to log4j 2.2. and I'm getting the following issues:
My AsyncLogger is working like a sync one. This is my config for this logger:
<RollingFile name="ACCESS_LOG" fileName="${sys:log.dir}vproxy_access.${date:yyyy-MM-dd}" filePattern="${sys:log.dir}vproxy_access.${date:yyyy-MM-dd}" append="true" bufferedIO="true" bufferSize="8192" immediateFlush="false"> <PatternLayout> <Pattern>%m%d{yyyy-MM-dd HH:mm:ss}%n </PatternLayout> <Policies/> </RollingFile>
<AsyncLogger name="LOGGER_ACCESS" level="info" includeLocation="true" additivity="false"> <AppenderRef ref="ACCESS_LOG"/> </AsyncLogger>
The log creation is correct but everything I log to this file is not buffered and the lines are committed immediately. I've been compared my config with others I've seen in other posts and I can't see what's wrong.
Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/ParameterizedMessage at org.apache.logging.log4j.message.ParameterizedMessageFactory.newMessage(ParameterizedMessageFactory.java:47) at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:737) at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:708) at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:314) at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:77) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.message.ParameterizedMessage at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) ... 6 more
When this error appears I'm not logging anything. The last line I log is shown correctly in its corresponding log.
2015-04-02 13:58:51 Starting messaging service ...
^[[?1;2c^[[?1;2c2015-04-02 13:59:06 Messaging service successfully started.
2015-04-02 13:59:06 Starting balancer test port ...
2015-04-02 13:59:06 Balancer test port successfully started.
Thanks in advance.
Joan.
Upvotes: 2
Views: 5487
Reputation: 36754
This is the expected behaviour. The background thread is simply keeping up with the log events your application is putting in the queue. Note that with log4j2, async logging will flush the buffer if the queue is empty, so results are immediately visible on disk. (See the docs for FileAppender immediateFlush.)
You may need to add the log4j-web module to your deployment. This is necessary to clean up log4j resources in a web application, and will also disable the shutdown hook. See https://logging.apache.org/log4j/2.x/manual/webapp.html
This one is trickier... Can you provide your full log4j2 config? Any chance there are 2 processes writing to the same file?
Upvotes: 6