Skip to content

Instantly share code, notes, and snippets.

@its-jd
its-jd / multi-handlers-logger.py
Created April 4, 2022 06:55 — forked from nguyendv/multi-handlers-logger.py
Python logger with multiple handlers (stream, file, etc.), so you can write log to multiple targets at once
import logging
from logging.handlers import RotatingFileHandler
def setup_logger():
MAX_BYTES = 10000000 # Maximum size for a log file
BACKUP_COUNT = 9 # Maximum number of old log files
# The name should be unique, so you can get in in other places
# by calling `logger = logging.getLogger('com.dvnguyen.logger.example')
logger = logging.getLogger('com.dvnguyen.logger.example')