简体   繁体   中英

Workflow logging using Log4J

I have defined two loggers MainLogger, SecondLogger which logs the debug statements to two separate files Main.log and Second.log respectively and defined the categories like

<appender name="MainLogger" class="org.apache.log4j.FileAppender">
        <param name="File" value="Main.log" />
</appender>

<appender name="SecondLogger" class="org.apache.log4j.FileAppender">
        <param name="File" value="Second.log" />
</appender>

<category name="Fully.Qualified.ClassA" additivity="false">
        <priority value="INFO" />
        <appender-ref ref="MainLogger" />
    </category>

<category name="Fully.Qualified.ClassB" additivity="false">
        <priority value="INFO" />
        <appender-ref ref="SecondLogger" />
</category>

The issue is, both the work flows share the ClassA and ClassB. So the Main.log is filled with high traffic work flow which is difficult to manage.

How do I limit the work flows to go to respective log files only?

Is there any solution to route the current thread log statements to one particular log file only?

Your problem seems like it might be solvable using the technique this question is using.

Basically, it looks like he's programatically setting up new appenders for every threaded instance of the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM