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.
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)
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With