Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

log4j, separating log streams by Java package

 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this can be done, but I can't figure out how to configure log4j.properties to send log messages from libraries/packages to separate streams. I get all of my output in one log file.

I've read all of "The complete log4j manual" by Ceki Gülcü, and just don't get it.
I want all msgs from com.pfarrell.* to go one place,
all msgs from com.foo.* to go to another
all from net.sourceforge.stripes to go to a third.

the log4j file looks like:


When I test it, it all goes to the same place

Test code looks like:



Thanks
 
author & internet detective
Posts: 40801
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pat,
I've been looking at Java Util Logging more than DebugLog lately, so I might be a bit confused. But doesn't the logger check whether you are in the right package when doing the output? I guess I don't follow how the test code would test this scenario if it is all in one place. Or did asking for the logger explicitly override that?

We have a forum for open source products. I'm going to move your post since it isn't IDE related.
 
Pat Farrell
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Pat,
I guess I don't follow how the test code would test this scenario if it is all in one place. Or did asking for the logger explicitly override that?

We have a forum for open source products. I'm going to move your post since it isn't IDE related.



The test code is not what you would use in real stuff, you would have one line to get the logger in each class. But the logger is selected by name (or by Foo.class) as an argument, so I can test with just one JUnit function

No problem moving it, I couldn't figure out where to post this.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pat,

I've got something very similar working, but with log4j.xml configuration as opposed to log4j.properties, any reason why you are using the .properties configuration style?
 
Pat Farrell
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martijn Verburg wrote:I've got something very similar working, but with log4j.xml configuration as opposed to log4j.properties, any reason why you are using the .properties configuration style?



Ease of editing.
I can edit properties with vi.
I can't with XML.

OT, I see no reason for all the XML love for things that are simple key/value pairs
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are actually some log4j features that are only supported if you use the xml configuration, I personally don't find editing XML in vi to be too much of a chore but YMMV . Nudge me tomorrow and I'll post what I have with my configuration at work, it might help you spot what's wrong.
 
Pat Farrell
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martijn Verburg wrote:There are actually some log4j features that are only supported if you use the xml configuration,


Interesting. I'd love to know more, examples, etc.
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Filters is the main feature that's supported in XML as opposed to properties IIRC, see Here for an example (scroll a little bit down).
 
You showed up just in time for the waffles! And this tiny ad:
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
reply
    Bookmark Topic Watch Topic
  • New Topic