Java log4j selects which file to write to

I need to write debugging messages from the same class to different files.
I mean, from the same class I need a specific debug statement to go to fileA, and another specific debug statement go to fileB.

If this is unclear, then I try to write network messages to a completely separate file than other loggin messages that this class issues.

If i do

<logger name="com.test.modules" additivity="false" >
    <priority value="debug"/>
    <appender-ref ref="netWorkCommunication"/>  
    <appender-ref ref="generalDebug"/>  
  </logger>  

Then the log from my class will go to both files (since it is from the same package).

How can I configure log4j so that I can choose which logging operator from classes to com.test.modulesgo to , which appender file ?

+5
source share
2

:

private static Logger log = Logger.getLogger(YourClass.class);
private static Logger networkLog = Logger.getLogger("network." + YourClass.class.getName());
private static Logger httpLog = Logger.getLogger("http." + YourClass.class.getName());

, .

+6

, . .

+2

All Articles