Logging Cookbook Release 3.9.5 Guido van Rossum and the Python development team June 01, 2021 Python Software Foundation Email: docs@python.org Contents 1 Using logging in multiple modules 2 2 Logging from multiple threads 4 3 Multiple handlers and formatters 5 4 Logging to multiple destinations 5 5 Configuration server example 6 6 Dealing with handlers that block 7 7 Sending and receiving logging events across a network 8 8 Adding contextual information to your logging output 10 8.1 Using LoggerAdapters to impart contextual information . . . . . . . . . . . . . . . . . . . . . . . 11 8.2 Using Filters to impart contextual information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 9 Logging to a single file from multiple processes 13 9.1 Using concurrent.futures.ProcessPoolExecutor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 10 Using file rotation 17 11 Use of alternative formatting styles 18 12 Customizing$_{LogRecord}$ 21 13 Subclassing QueueHandler - a ZeroMQ example 22 14 Subclassing QueueListener - a ZeroMQ example 22 15 An example dictionary-based configuration 23 16 Using a rotator and namer to customize log rotation processing 24 17 A more elaborate multiprocessing example 24 18 Inserting a BOM into messages sent to a SysLogHandler 28 1