aspose file tools*
The moose likes Other Open Source Projects and the fly likes log4j: Reading Log level from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j: Reading Log level from DB" Watch "log4j: Reading Log level from DB" New topic
Author

log4j: Reading Log level from DB

Aakash Parashar
Ranch Hand

Joined: Jul 25, 2005
Posts: 118

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%
http://java-application-programming.blogspot.in
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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: 118

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: 3274
    
    5

Thanks for letting us know Aakash, interesting stuff!
Aakash Parashar
Ranch Hand

Joined: Jul 25, 2005
Posts: 118

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j: Reading Log level from DB
 
Similar Threads
java logging in JApplet
About echo in ant
Can Log4j read two properties?
how to suppress java.util.logging messages
Using jdk1.4 logging api with weblogic