Multiple calls to$_{logging.getLogger('someLogger')}$ return a reference to the same logger object. This is true not only within the same module, but also across modules as long as it is in the same Python interpreter process. It is true for references to the same object; additionally, application code can define and configure a parent logger in one module and create (but not configure) a child logger in a separate module, and all logger calls to the child will pass up to the parent. Here is a main module: This page contains a number of recipes related to logging, which have been found useful in the past. Author Vinay Sajip <vinay_sajip at red-dove dot com> 1 Using logging in multiple modules import logging import auxiliary_module # create logger with 'spam_application' logger=logging.getLogger('spam_application ') logger.setLevel(logging .DEBUG) # create file handler which logs even debug messages fh =logging.FileHandler('spam.log ') fh.setLevel(logging .DEBUG) # create console handler with a higher log level ch =logging.StreamHandler() ch.setLevel(logging .ERROR) # create formatter and add it to the handlers formatter =logging.Formatter(' %(asctime)s - %(name)s - %(levelname)s - %(message)s ↪ → ') fh.setFormatter(formatter) ch.setFormatter(formatter) # add the handlers to the logger logger.addHandler(fh) logger.addHandler(ch) (continues on next page) 2 19 Implementing structured logging 28 20 Customizing handlers with$_{dictConfig()}$ 30 21 Using particular formatting styles throughout your application 32 21.1 Using LogRecord factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 21.2 Using custom message objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 22 Configuring filters with dictConfig() 33 23 Customized exception formatting 34 24 Speaking logging messages 35 25 Buffering logging messages and outputting them conditionally 36 26 Formatting times using UTC (GMT) via configuration 38 27 Using a context manager for selective logging 39 28 A CLI application starter template 41 29 A Qt GUI for logging 43 Index 48