This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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
 
 
subject: log4j: How to write to multiple log files?
 
Similar Threads
Trying to get verbose log4j info
Websphere 6.1 - Apache commons logging with log4j does not work
Logger don't write info and debug in Log file
log4j multiplelocation logging
Logging SQL statements