• 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

log to differnt files

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have to log the logs from 2 differnt packages to differnt log files. How do I set the config in log4j.properties.

package com.foo.X has to go to log1.log and package com.foo except com.foo.X , all other package like com.foo.K com.foo.T has to go to log2.log

Any ideas please?
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really don't know how to do that with the log4j.properties.. Now, log4j does support using an log4j.xml file to set it up. usually its the same kind of convenience, of just dropping the log4j.xml into the top of the classpath instead of (remove and replace) the log4j.properties. Or if you do any other kind of elaborate set up logging by system property to log4j config file path.

The log4j.xml is more flexible, and powerful for setting up more elaborate kinds of things like different log files by package as you are looking to do.

Have a look at http://wiki.apache.org/logging-log4j/Log4jXmlFormat

they have an example towards the end where using the log4j.xml to do package specific logging.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you stuck? Are you using the additivity flag to keep com.foo.X logging out of log2.log?

After you define logger/appender for com.foo.X set additivity false on com.foo.X :

log4j.additivity.com.foo.X = false

You can search on additivity in this forum for examples.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my log4j file




As you can see form the file, I want com.foo.X to go to log2.log and all the remaining package logs to go to log1.log.

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 Mary,

One idea i have and applied in my project.

Do as follows--

1. Create a class with logger and create methods which call nothing but DEBUG()/INFO()/ ... etc.
2. Configure the above created class in log4j.propertis/log4j.xml.
3. Now call the above created methods to log messages other than package com.foo.X.

For full details you may follow this.
Don't get confused by the subject line used in the given url, what i described above, is available there.

Thanks,
Tanzy.

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply tanzy akhtar...I am not allowed to write any java class for this.. Below config worked fine for me

 
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
That's really great that the problem has been resolved. Congrats.
And thanks for sharing the solution.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic