This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j, separating log streams by Java package

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic