• 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

Log4j - log in different files, same jar , different Main classes

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project with the 2 java classes having main method.
These 2 classes are to be executed for 2 different purposes on the same machine at same time in different java process.
These process share the same log4j.properties file as :

[code]
log4j.rootCategory=DEBUG,FILE, FILE2

log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.MaxFileSize=5MB
log4j.appender.FILE.MaxBackupIndex=50
log4j.appender.FILE.File=C:/Logs/Log1.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{dd MMM yyyy HH.mm.ss.SSS} : %c : %m %n

log4j.appender.FILE2=org.apache.log4j.RollingFileAppender
log4j.appender.FILE2.MaxFileSize=5MB
log4j.appender.FILE2.MaxBackupIndex=50
log4j.appender.FILE2.File=C:/Logs/Log2.log
log4j.appender.FILE2.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE2.layout.ConversionPattern=%d{dd MMM yyyy HH.mm.ss.SSS} : %c : %m %n
[/code/

However , when I executed one java class, it is logging to both the log files as Log1 & Log2.
How should I configure this in java code, so that 1st java class/process will log to Log1.log and 2nd to Log2.log?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do have similar requirement. Please help me out.
 
Ranch Hand
Posts: 50
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I have requirement & same prob..
anyone plzz help
 
Srikanth Madasu
Ranch Hand
Posts: 50
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did something like this

log4j.AppLogger=ALL, appfile
log4j.DaoLogger=ALL, daofile

log4j.appender.appfile=org.apache.log4j.RollingFileAppender
log4j.appender.appfile.maxFileSize=100KB
log4j.appender.appfile.maxBackupIndex=5
log4j.appender.appfile.File=app.log
log4j.appender.appfile.threshold=info
log4j.appender.appfile.layout=org.apache.log4j.PatternLayout
log4j.appender.appfile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

log4j.appender.daofile=org.apache.log4j.RollingFileAppender
log4j.appender.daofile.maxFileSize=100KB
log4j.appender.daofile.maxBackupIndex=5
log4j.appender.daofile.File=dao.log
log4j.appender.daofile.threshold=info
log4j.appender.daofile.layout=org.apache.log4j.PatternLayout
log4j.appender.daofile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

And in my DAo class I declared as
private static Logger log = Logger.getLogger("log4j.DaoLogger");

And in my appclass I declared
private static Logger log = Logger.getLogger("log4j.AppLogger");

But i get following error:

log4j:WARN No appenders could be found for logger (log4j.AppLogger).
log4j:WARN Please initialize the log4j system properly.

Am I missing something?
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please start a new thread, we try not to wake the zombies around here
 
You can't expect to wield supreme executive power just because
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