Search code examples
pythonloggingpython-logging

Dynamically changing log level without restarting the application


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

This is for an application running on a server, I want sys admins to be able to change a config file that is picked during run time by the application and change the log level dynamically.


Solution

  • 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)