Python dual-logging setup (console and log file) supporting different log levels and colorized output
✓ Published0🌍 Public
Aalvinthai
Last edited May 15, 2020
Created on Dec 18, 2020
This example demonstrates a dual-logging setup for Python applications, sending console output and file logs to separate destinations with distinct severity levels and formatting. The code defines a `LogFormatter` class that applies ANSI color codes to console messages based on log level, while writing plain, uncolored records to the log file. It uses the standard `logging` module with `StreamHandler` for stdout and `FileHandler` for file output, configuring the root logger to handle debug through critical messages. A template controls the output format, including timestamps, thread names, and log levels.
AI-generated description