Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple log files with log4j  RSS feed

 
Jim Lang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking at log4j for use as a logging subsystem and have read the available docs. However, I want to use it to define multiple loggers - so that I can send different kinds of messages to different log files (DEBUG to a debug.log, INFO to an info.log, etc) from the same application. Another use would be to separate log files in a particular application by subject area - so database-related logging goes to a db.log, jndi-related logging to a jndi.log, etc.
Can anyone tell me whether this kind of functionality is already built into log4j ? I can write a related set of classes to do this for me but want to avoid re-inventing it if it's already a feature.
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great idea...although I'm not sure I know how to do it.
I love log4j, I just wish there was a little more documentation. I've included a log config that I use, which writes all output to both the console and a log file. Maybe you can use this to get started.
I would really like to see your solution on this.
log4j.rootLogger=info, logfile, console

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m%n
log4j.logger.com.mycompany=INFO

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=logs/myapp.log
log4j.appender.logfile.MaxFileSize=1000KB
# Number of backups to keep
log4j.appender.logfile.MaxBackupIndex=60
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%p %t %c - %m%n
[ July 26, 2002: Message edited by: Chris Reeves ]
[ July 26, 2002: Message edited by: Chris Reeves ]
[ July 26, 2002: Message edited by: Chris Reeves ]
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although this question was asked a while ago, I came across it when doing some searches and figured others might also, so I thought I'd post this reply...
See Sorting Log Messages By Levelat the Apache website for info on how to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!