wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes log4j, separating log streams by Java package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j, separating log streams by Java package" Watch "log4j, separating log streams by Java package" New topic
Author

log4j, separating log streams by Java package

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

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
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

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.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

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
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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

Joined: Aug 11, 2007
Posts: 4650
    
    5

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
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: log4j, separating log streams by Java package