advanced logging multiple handlers as suggested in the previous section we can create multiple handlers to send log messages to different locationsfor example from the consoleto files and even email servers the following program illustrates setting up both file handler and console handler for module level logger to do this we create two handlers the file_handler and the console_handler as side effect we can also give them different log levels and different formatters in this case the file_handler inherits the log level of the logger itself (which is debugwhile the console_handler has its log level set explicitly at warning this means different amounts of information will be logged to the log file than the console output we have also set different formatters on each handlerin this case the log file handler' formatter provides more information than the console handlers formatter both handlers are then added to the logger before it is used multiple handlers and formatters import logging set up the default root logger to do nothing logging basicconfig(handlers=[logging nullhandler()]obtain the module level logger and set level to debug logger logging getlogger(__name__logger setlevel(logging debugcreate file handler file_handler logging filehandler('detailed log'create console handler with higher log level console_handler logging streamhandler(console_handler setlevel(logging warningcreate formatter for the file handler fh_formatter logging formatter%(name) %(funcname) %(message) 'datefmt% 'file_handler setformatter(fh_formatter-% % :% :%