Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created April 12, 2019 15:33
Show Gist options
  • Save vlad-bezden/6e6e936b3e2a6c91c4fd7321914a8999 to your computer and use it in GitHub Desktop.
Save vlad-bezden/6e6e936b3e2a6c91c4fd7321914a8999 to your computer and use it in GitHub Desktop.
An example of how to configure logger to log output to console as well as to rotation file. There will be max 10 files created with each 1MB max
import logging as logger
from logging.handlers import RotatingFileHandler
logger.basicConfig(
level=logger.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[
RotatingFileHandler(
"log_info.log", maxBytes=1_000_000, backupCount=10
),
logger.StreamHandler(),
],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment