• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Multiple log files with log4j

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic