• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two log files for two different classes in the same package

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nila,
Any update from your side?
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic