Last active
March 6, 2017 07:34
-
-
Save ejhari/fba3eb2e46152333942f118f848671ea to your computer and use it in GitHub Desktop.
Quick and Simple Logger
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 | |
import logging.handlers | |
LOG_FILE = '/var/log/my_app/server.log' | |
# Set up a specific logger with our desired output level | |
logger = logging.getLogger('my_app') | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
logger.setLevel(logging.DEBUG) | |
# Add the log message handler to the logger | |
ch = logging.StreamHandler() | |
ch.setFormatter(formatter) | |
logger.addHandler(ch) | |
fh = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1000000, backupCount=5) | |
fh.setFormatter(formatter) | |
logger.addHandler(fh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment