Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Multiple log files with log4j

 
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.
 
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 ]
 
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.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic