levelas appropriate create handler objects by instantiating one of the various types of handlers (filehandlerstreamhandlersockethandlerand so onand set an appropriate level create message formatter objects and attach them to the handler objects using the setformatter(method attach the handler objects to the logger objects using the addhandler(method because the configuration of each step can be somewhat involvedyour best bet is to put all the logging configuration into single well-documented location for exampleyou might create file applogconfig py that is imported by the main program of your applicationapplogconfig py import logging import sys set the message format format logging formatter("%(levelname)- %(asctime) %(message) "create handler that prints critical level messages to stderr crit_hand logging streamhandler(sys stderrcrit_hand setlevel(logging criticalcrit_hand setformatter(formatcreate handler that prints messages to file applog_hand logging filehandler('app log'applog_hand setformatter(formatcreate top-level logger called 'appapp_log logging getlogger("app"app_log setlevel(logging infoapp_log addhandler(applog_handapp_log addhandler(crit_handchange the level on the 'app netlogger logging getlogger("app net"setlevel(logging errorif changes need to be made to any part of the logging configurationhaving everything in one location makes things easier to maintain keep in mind that this special file only needs to be imported once and in only one location in the program in other parts of the code where you want to issue log messagesyou simply include code like thisimport logging app_log logging getlogger("app"app_log critical("an error occurred"the logging config submodule as an alternative to hard-coding the logging configuration in python codeit is also possible to configure the logging module through the use of an ini-format configuration file to do thisuse the following functions found in logging config fileconfig(filename [defaults [disable_existing_loggers]]reads the logging configuration from the configuration file filename defaults is lib fl ff