• 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

log4j: Reading Log level from DB

 
Ranch Hand
Posts: 123
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
Hmm, not that I've heard of, can I ask _why_ you want to read it from a DB?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
Thanks for letting us know Aakash, interesting stuff!
 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The only cure for that is hours of television radiation. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic