Skip to content

Instantly share code, notes, and snippets.

@ejhari
Last active March 6, 2017 07:34
Show Gist options
  • Save ejhari/fba3eb2e46152333942f118f848671ea to your computer and use it in GitHub Desktop.
Save ejhari/fba3eb2e46152333942f118f848671ea to your computer and use it in GitHub Desktop.
Quick and Simple Logger
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