advanced logging as can be seen from this the default formatter is now configured for filehandler this filehandler adds the log message level before the log message itself programmatically setting the handler it is also possible to programmatically create handler and set it for the logger this is done by instantiating one of the existing handler classes (or by subclassing an existing handler such as the root handler class or the filehander etc the instantiated handler can then be added as handler to the logger (remember the logger can have multiple handlers this is why the method is called addhandler (rather than something such as sethandleran example of explicitly setting the filehandler for logger is given belowimport logging empty basic config turns off default console handler logging basicconfig(logger logging getlogger(__name__logger setlevel(logging debugcreate file handler which logs to the specified file file_handler logging filehandler('detailed log'add the handler to the logger logger addhandler(file_handler'applicationcode def do_something()logger debug('debug message'logger info('info message'logger warning('warn message'logger error('error message'logger critical('critical message'logger info('starting'do_something(logger info('done'the result of running this code is that log file is created with the logged messages