Skip to content

Instantly share code, notes, and snippets.

@bilbo3000
Last active March 12, 2017 06:51
Show Gist options
  • Save bilbo3000/f26651e2fb817a7d847040070d38b05b to your computer and use it in GitHub Desktop.
Save bilbo3000/f26651e2fb817a7d847040070d38b05b to your computer and use it in GitHub Desktop.
Python logging example
import logging
from logging import Formatter
from logging.handlers import TimedRotatingFileHandler
# Setup Logger
LOGGER = logging.getLogger("my logger")
LOGGER.setLevel(logging.INFO)
handler = TimedRotatingFileHandler("/my/log/file.log", when="midnight", interval=1, utc=True)
handler.setFormatter(Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
LOGGER.addHandler(handler)
LOGGER.info("This is a message")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment