Last active
March 12, 2017 06:51
-
-
Save bilbo3000/f26651e2fb817a7d847040070d38b05b to your computer and use it in GitHub Desktop.
Python logging example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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