dcsimg
Want 2 loggers in same class writing to different files
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andreas_Rutvik
Posted On:   Tuesday, July 27, 2004 07:41 AM

I have a class where I need to write log-statements to 2 different files. How do I set up this in my log4j.properties file and in the java-class ? For the moment, my log4j.properties looks like this : log4j.rootLogger=DEBUG, console, file, perf # appender that uses System.out log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=[%d{dd/MM/y HH:mm:ss}][%-10.10t][%1p] %c - %m%n log4j.appender.console.threshold=DEBUG # appender to write to a log file log4j.appender.file=org.apache.log4j.DailyRollingFileAppe   More>>

I have a class where I need to write log-statements to 2 different files. How do I set up this in my log4j.properties file and in the java-class ?

For the moment, my log4j.properties looks like this :


log4j.rootLogger=DEBUG, console, file, perf



# appender that uses System.out

log4j.appender.console=org.apache.log4j.ConsoleAppender

log4j.appender.console.layout=org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern=[%d{dd/MM/y HH:mm:ss}][%-10.10t][%1p] %c - %m%n

log4j.appender.console.threshold=DEBUG




# appender to write to a log file

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender

log4j.appender.file.file=debug.log

log4j.appender.file.append=false

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=[%d{dd/MM/y HH:mm:ss}][%-10.10t][%1p] %c - %m%n

#log4j.appender.file.threshold=INFO




# appender to write performance details

log4j.appender.perf=org.apache.log4j.DailyRollingFileAppender

log4j.appender.perf.file=perf.log

log4j.appender.perf.append=false

log4j.appender.perf.layout=org.apache.log4j.PatternLayout

log4j.appender.perf.layout.ConversionPattern=[%d{dd/MM/y HH:mm:ss}][%-10.10t][%1p] %c - %m%n





# logger level depending on class

log4j.logger.perf=DEBUG,perf

log4j.logger.channels.comms.in=DEBUG

log4j.logger.channels.ChannelAC=DEBUG



And the important in the Java class looks like this :




private static final Logger logger = Logger.getLogger ( ChannelAC.class );


private static final Logger perfLogger = Logger.getLogger ( "perf" );




I want to be able to write code like :


// log this to file perf.log

perfLogger.logDebug("some debugging info");



//log this to debug.log

logger.logDebug("some debugging info");


Regards
/Andreas    <<Less
About | Sitemap | Contact