• 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

New to log4j - need some advice

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
author
Posts: 3285
13
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 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!
 
K DeLucia
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! That helps! I'll have to play with it a while to see what works best.
 
Martijn Verburg
author
Posts: 3285
13
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
You're welcome
reply
    Bookmark Topic Watch Topic
  • New Topic