handlers given that this is lot more code than using the basicconfig(functionthe question here might be 'why bother?the answer is two foldyou can have different handlers for different loggers rather than setting the handler to be used centrally each handler can have its own format set so that logging to file has different format to logging to the console we can set the format for the handler by instantiating the logging formatter class with an appropriate format string the formatter object can then be applied to handler using the setformatter(method on the handler object for examplewe can modify the above code to include formatter that is then set on the file handler as shown below create file handler which logs to the specified file file_handler logging filehandler('detailed logcreate formatter for the file_handler formatter logging formatter('%(asctime) %(funcname) %(message)sfile_handler setformatter(formatterlogger addhandler(file_handlerthe log file now generated is modified such that each message includes time stampthe function name (or module if at the module levelas well as the log message itself