| Author |
Two log files for two different classes in the same package
|
Nila dhan
Ranch Hand
Joined: Sep 15, 2005
Posts: 160
|
|
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
Joined: Jul 19, 2009
Posts: 110
|
|
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.
|
Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8210
|
|
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
|
[My Blog] [JavaRanch Journal]
|
 |
Tanzy Akhtar
Ranch Hand
Joined: Jul 19, 2009
Posts: 110
|
|
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
Joined: Jul 19, 2009
Posts: 110
|
|
Hi Nila,
Any update from your side?
|
 |
Omar Al Kababji
Ranch Hand
Joined: Jan 13, 2009
Posts: 357
|
|
|
Never done this before, but I think you could write you own file appender may be this link could help you.
|
Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
|
 |
 |
|
|
subject: Two log files for two different classes in the same package
|
|
|