Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two log files for two different classes in the same package

 
Nila dhan
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
My requirement is , two classes must each have a log file. The two classes are in the same package. I am using log4j for implementing this. Below is the log4j.properties. Two log files are created when either of the class is executed. Any suggestions would be helpful. Thanks in advance

 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nila,

The same kind of problem i also faced.

Well what i understand it's because of initialization of log4j.
Once log4j gets initialized, it will behave whatever configured in log4j.properties or log4j.xml.

I didn't find any way to lazy initialize these things.

It would be graetful to share the solution if you find out.


Thanks,
Tanzy.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although i did not get the exact question you are asking, your configuration has a root logger which configured to log to both the log files:

log4j.rootLogger=debug, logfile,Importslogfile


So every log statement is going to end up in both those files
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran,

What i think, Nila has two classes in the same package.
Both claases have some log statements and also their respective appender.
That to log the both classes, each class has their own fileappender.

For example let two classes A and B.
The two file appeneder configured in log4j.properties are logfile and Importslogfile .

Suppose logfile is for class A and Importslogfile for class B.

Now if we execute the class A only, it will log into logfile that is CFlogs.log.
We did not executed class B. But still Importslogfile will get initiated and corresponding ItF.log of 0kb (zero kb)
gets created. And this is the question of Nila, that is there any to avoid creation of ItF.log until we execute the class B.

Am i right Nila?


Thanks,
Tanzy.
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nila,
Any update from your side?
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never done this before, but I think you could write you own file appender may be this link could help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic