permaculture playing cards*
The moose likes Other Open Source Projects and the fly likes New to log4j - need some advice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "New to log4j - need some advice" Watch "New to log4j - need some advice" New topic
Author

New to log4j - need some advice

K DeLucia
Ranch Hand

Joined: Apr 11, 2008
Posts: 68
I'm fairly new to Java and completely new to log4j. A consultant that we had in recently strongly recommended that we use log4j. (Up until this point I just used system.out when I needed to log a message). I've been meaning to look into it, but he convinced me to do it now. So, I did a lot of reading trying to get an idea of the best way to set things up, but I'm still not sure how to begin. Right now we have two java applications running on JBoss. Eventually, we will have many java applications so I would really like to set this up right from the start.

The consultant recommended a separate log for each application and he recommended that we use a separate log4j.xml within each application to control the logging for that application. In that case, I believe the log4j.xml would be within each jar/war/ear. To me that sounds like a bad idea. If you need to change the logging config, you need to recompile/redeploy.

I understand that we could put all the configuration into the jboss-log4j.xml, but I read that if I need to change the logging for one application, by changing the 'master file', it will affect all the applications currently using that file and will affect performance.

Can/should I have multiple log4j.xml files on the server, outside of my application/war? What do I name them so they will be recognized?

My other question concerns the migration from testing/development to production. During development I would assume I would have a lot of logging going on to troubleshoot and work through issues. But in production I would want much less logging. How do I handle that? Do I need to remember to change the logging levels in log4j.xml prior to deploying in production? What is the best way to handle that?
(I should mention that we don't have a clearly defined process for moving between development, qa, production yet - but that's another whole subject entirely.)

Any help, info, pointers, experiences are welcome! Thanks!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

You can achieve the separate logs in Jboss in one of two ways:

1.) Have separate log4j.xml files (say appA-log4j.xml and appB-log4j.xml) in either the $JBOSS_HOME/server/<your server instance>/conf or $JBOSS_HOME/server/<your server instance>/deploy

Your applications will hjave to directly reference those specific files

2.) You can have all of the configuration in the jobss-log4j.xml file with something like:



With regards to changing the log4j settings per environment you really have 2 choices

1.) Have a separate version for each environment and copy in the correct one at deployment time.
2.) Have one file but have parts of it filtered (each build time replacement bu ANT or Maven).

Hope that Helps!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
K DeLucia
Ranch Hand

Joined: Apr 11, 2008
Posts: 68
Thanks! That helps! I'll have to play with it a while to see what works best.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to log4j - need some advice