Created
May 9, 2017 08:14
-
-
Save mmasashi/63aea802463406dc5367ad18e592c0da to your computer and use it in GitHub Desktop.
Initialize logging for Flask
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
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