Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically changing log level without restarting the application

Is it possible to change the log level using fileConfig in python without restarting the application. If it cannot be achieved through fileConfig is there some other way to get the same result?

Update: This was for an application running on a server, I wanted sys admins to be able to change a config file that would be picked during run time by application and change the log level dynamically. I was working with gevent at that time hence I've added my code as one of the answers which uses inotify to pick changes to config file.

like image 506
opensourcegeek Avatar asked Oct 27 '13 11:10

opensourcegeek


People also ask

How do you change the logging level?

To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

How do you change the log level in production?

Option 1: Using the Spring Boot Admin In this option, your application needs to enable the spring actuator and get it registered with Spring Boot Admin. The user will use the spring boot admin UI to change the log levels. Merely select the logger and change the log level in just click of a button.

How do you change the log level in log4j2 at runtime?

You can set a logger's level with the class Configurator from Log4j Core. BUT be aware that the Configurator class is not part of the public API. If you wish to change the root logger level, do something like this : LoggerContext ctx = (LoggerContext) LogManager.


1 Answers

fileConfig is a mechanism to configure the log level for you based on a file; you can dynamically change it at any time in your program.

Call .setLevel() on the logging object for which you want to change the log level. Usually you'd do that on the root:

logging.getLogger().setLevel(logging.DEBUG) 
like image 169
Martijn Pieters Avatar answered Oct 25 '22 16:10

Martijn Pieters