| Author |
log4j: Reading Log level from DB
|
Aakash Parashar
Ranch Hand
Joined: Jul 25, 2005
Posts: 109
|
|
Hi Forum, Normally log level is set in log4j.properties file. Is there any way to set log level kept in Database? In short I don't want to read log level from properties file. Thanks
|
Your's Aakash
SCJP 1.4 96%, SCBCD 1.3 94%
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
|
Hmm, not that I've heard of, can I ask _why_ you want to read it from a DB?
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
Uli Hofstoetter
Ranch Hand
Joined: Nov 24, 2006
Posts: 57
|
|
You could read the log level from the database before configuering log4j, set the log level as a system property and reference this property in the log4j properties. I never did this with the loglevel, but with the log file path. Java Code: log4j.xml:
|
SCEA5, Certified ScrumMaster
|
 |
Aakash Parashar
Ranch Hand
Joined: Jul 25, 2005
Posts: 109
|
|
Hi Friends, I got answer of my question. PropertyConfigurator - this class is present on log4j. PropertyConfigurator.configure(prop); //prop is a Property object The configure method is used to load the properties which are present in a Property type of object. The key and value in Property type of object can be read from DB, properties file or any resource present inside or outside object. PropertyConfigurator.configure() method will set the properties in the log4j environment. [ December 03, 2008: Message edited by: Aakash ]
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
|
Thanks for letting us know Aakash, interesting stuff!
|
 |
Aakash Parashar
Ranch Hand
Joined: Jul 25, 2005
Posts: 109
|
|
Originally posted by Martijn Verburg: Hmm, not that I've heard of, can I ask _why_ you want to read it from a DB?
We are putting log4j properties in a property file which is clubbed in EAR deployed. So for changing the log level we have to pull the properties file from EAR for changing and after changing we have to redeploy the EAR. To escape from all this mess and complex process we were thinking of putting log level in DB.
|
 |
 |
|
|
subject: log4j: Reading Log level from DB
|
|
|