Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change log level in log4j at runtime

 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a small requirement where the default log level is info, but if the user wants to invoke the Java program with debug level, the Debug should start off. I am trying to achieve this using this code..


When I do this, the debug statement at the end does not print.
Then I thought may be the root logger level is not propagated after the initialization at start up, so I tried this


The info statement prints "this is info" then the next info statement prints "log level is DEBUG" the next statement prints true but the intermediate debug statement does not print.

I have done this before in a Web app and it works just fine. I do not understand what is going on. Can someone please help me understand this.
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saagar, would you know if there are any other loggers (other than root) which may be conflicting with your setup?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saagar,

Where (i.e. in which "appender") does it not print? On the CONSOLE or in some file? Check the value of "Threshold" attribute for the appender in which you expect this message to be logged. Maybe the Threshold value is set to INFO, because of which the debug statements are ignored in that appender.
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul: I dont have custom settings for each logger based on package or class structure, so the root logger settings take effect in each, but when I update the root logger that doesn't get updated in the current loggers.

@Jaikiran: The idea is to give the user the ability to debug at command line before launching the program. The threshold is info but I want to be able to selectively change it to debug at runtime..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic