...
/Configuring Logs for Work and Pleasure
Configuring Logs for Work and Pleasure
We'll cover the following...
The logging module can be configured 3 different ways. You can configure it using methods (loggers, formatters, handlers) like we did earlier in this article; you can use a configuration file and pass it to fileConfig(); or you can create a dictionary of configuration information and pass it to the dictConfig() function. Let’s create a configuration file first and then we’ll look at how to execute it with Python. Here’s an example config file:
Press + to interact
[loggers]keys=root,exampleApp[handlers]keys=fileHandler, consoleHandler[formatters]keys=myFormatter[logger_root]level=CRITICALhandlers=consoleHandler[logger_exampleApp]level=INFOhandlers=fileHandlerqualname=exampleApp[handler_consoleHandler]class=StreamHandlerlevel=DEBUGformatter=myFormatterargs=(sys.stdout,)[handler_fileHandler]class=FileHandlerformatter=myFormatterargs=("config.log",)[formatter_myFormatter]format=%(asctime)s - %(name)s - %(levelname)s - %(message)sdatefmt=
You’ll notice that we have two loggers specified: ...