File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j: Reading Log level from DB

 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, not that I've heard of, can I ask _why_ you want to read it from a DB?
 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for letting us know Aakash, interesting stuff!
 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic