Skip to content

Instantly share code, notes, and snippets.

@mmasashi
Created May 9, 2017 08:14
Show Gist options
  • Save mmasashi/63aea802463406dc5367ad18e592c0da to your computer and use it in GitHub Desktop.
Save mmasashi/63aea802463406dc5367ad18e592c0da to your computer and use it in GitHub Desktop.
Initialize logging for Flask
def setup_logging():
import logging
import os
from logging.handlers import RotatingFileHandler
from logging import Formatter
handler = RotatingFileHandler('log/flask.log', maxBytes=10000, backupCount=1)
process_id = os.getpid()
handler.setFormatter(Formatter(
#'[%(asctime)s] [%(levelname)s]: %(message)s [in %(pathname)s:%(lineno)d]' # for debug
'[%(asctime)s #' + str(process_id) + '] [%(levelname)s]: %(message)s'
))
handler.setLevel(logging.DEBUG)
app.logger.addHandler(handler)
setup_logging()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment