This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes log4j: How to write to multiple log files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "log4j: How to write to multiple log files?" Watch "log4j: How to write to multiple log files?" New topic
Author

log4j: How to write to multiple log files?

lydia edward
Greenhorn

Joined: Feb 02, 2011
Posts: 11
Hi,

I am using log4j for logging events in my application and I want to log various actions from various classes into two different log files.
Only the classes from 3 or 4 packages must log to "aaa.log" file and all other classes must log to "bbb.log" file.
Can someone please help me out in this and let me know how to go about this?


I tried the following log4j.properties file...but this is creating only the Logs.log file file. Please help!


log4j.rootLogger=DEBUG

log4j.logger.abc.xyz.xxx.controller=DEBUG, default
log4j.appender.AdminLogAppender=org.apache.log4j.FileAppender
log4j.appender.AdminLogAppender.File=../logs/AdminLogs.log
log4j.appender.AdminLogAppender.layout=org.apache.log4j.PatternLayout

log4j.logger.abc.xyz.yyy.controller=DEBUG, default
log4j.appender.AdminLogAppender=org.apache.log4j.FileAppender
log4j.appender.AdminLogAppender.File=../logs/AdminLogs.log
log4j.appender.AdminLogAppender.layout=org.apache.log4j.PatternLayout

log4j.logger.abc.xyz=DEBUG, default
log4j.appender.default=org.apache.log4j.FileAppender
log4j.appender.default.File=../logs/Logs.log
log4j.appender.default.layout=org.apache.log4j.PatternLayout

log4j.appender.default.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.AdminLogAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

Regards
Lydia
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: log4j: How to write to multiple log files?
 
It's not a secret anymore!