You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Xin Lin (Jira)" <ji...@apache.org> on 2022/10/06 00:27:00 UTC

[jira] [Comment Edited] (LOG4J2-3611) Log4j2 Writing to the rolled file

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

Xin Lin edited comment on LOG4J2-3611 at 10/6/22 12:26 AM:
-----------------------------------------------------------

Hi [~rgoers] , thank you so much for your reply!

I have tried to use BasicContextSelector, but it didn't help. What I did here is set log4j2.contextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector to system properties. But we still have the rollover issue. 

And I found that the jboss logging can record all log events - for the jboss log events/wildfly or some other log events, they perform good, but for the log4j log events, it will use the Console appender in log4j2.xml to record, and then wrap it into the jboss pattern. And that cause a wrong format of the log event in the log file. 

For example, if there is a class use Log4j Logger, it will first use the pattern specified in Console appender (log4j2.xml), and then as we need to record the event in a log file, it will then wrap it again in the format that specified in the file handler (standalone.xml). 

As shown below, "05:01:23,136 ERROR [xxx.xxx] xxxxxxxxxxxxxxxxxxxx" part follow the pattern in log4j2 (this part will be treated as %s in jboss logging later), and "05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC)" follow the pattern in jboss logging.

Ideally, we don't want the part "05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC)".  But if I change the format in standalone.xml, other log events format will be affected. 

05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC) 05:01:23,136 ERROR [xxx.xxx] xxxxxxxxxxxxxxxxxxxx

I tried the method mentioned here: [https://stackoverflow.com/questions/60302983/jboss-eap-7-2-wraps-stdout-and-stderr-messages] and I see the format work fine in the console, but we need thosse logs in the log file. And when I change handler ref to the file handler, it still got the error format. 

Do you have any ideas about this? 


was (Author: JIRAUSER296247):
Hi [~rgoers] , thank you so much for your reply! I have tried to use BasicContextSelector, but it didn't help. 

And I found that the jboss logging can record all log events - for the jboss log events/wildfly or some other log events, they perform good, but for the log4j log events, it will use the Console appender in log4j2.xml to record, and then wrap it into the jboss pattern. And that cause a wrong format of the log event in the log file. 

For example, if there is a class use Log4j Logger, it will first use the pattern specified in Console appender (log4j2.xml), and then as we need to record the event in a log file, it will then wrap it again in the format that specified in the file handler (standalone.xml). 

As shown below, "05:01:23,136 ERROR [xxx.xxx] xxxxxxxxxxxxxxxxxxxx" part follow the pattern in log4j2 (this part will be treated as %s in jboss logging later), and "05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC)" follow the pattern in jboss logging.

Ideally, we don't want the part "05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC)".  But if I change the format in standalone.xml, other log events format will be affected. 

05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC) 05:01:23,136 ERROR [xxx.xxx] xxxxxxxxxxxxxxxxxxxx

I tried the method mentioned here: [https://stackoverflow.com/questions/60302983/jboss-eap-7-2-wraps-stdout-and-stderr-messages] and I see the format work fine in the console, but we need thosse logs in the log file. And when I change handler ref to the file handler, it still got the error format. 

Do you have any ideas about this? 

> Log4j2 Writing to the rolled file
> ---------------------------------
>
>                 Key: LOG4J2-3611
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3611
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders, Configuration, Web/Servlet
>    Affects Versions: 2.17.2
>            Reporter: Xin Lin
>            Priority: Major
>
> I am migrating log4j 1 to log4j2 in a jboss application. 
> I added log4j-api & log4j-core & log4j-1.2-api dependencies, I have added log4j2.xml and setup proper system config, and then application good to start. 
> This issue happens when the rolling action triggerred. When the rolled file created, I see that some logs written in the new log file, but some logged in the rolled file. 
> I turned on the TRACE mode, and can see some logs show that Log4j2 RollingFileManager execute the FileRenameAction. So we have two files (app.log & app.log.2022-09-27). 
> But some log events went to app.log, some went to app.log.2022-09-27. 
> According to the log format, I think the new logs in rolled file is written by Log4j2, the log content is like following: 
> 05:01:23,150 INFO [stdout] (Log4j2-AsyncAppenderEventDispatcher-2-ASYNC) 05:01:23,136 ERROR [xxx.xxx] xxxxxxxxxxxxxxxxxxxx
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)