Answer the question
In order to leave comments, you need to log in
Flask, Celery and RotatingFileHandler - how to make friends?
The same code is called to initialize App and Celery:
# -*- coding: utf-8 -*-
"""Create an application instance."""
from flask.helpers import get_debug_flag
from appdata.app import create_app
from appdata.settings import DevConfig, ProdConfig
from appdata.extensions import celery
from appdata.utils import init_celery
CONFIG = DevConfig if get_debug_flag() else ProdConfig
app = create_app(CONFIG)
init_celery(app, celery)
def register_logger(app):
"""Register application logger."""
import os.path
if not os.path.exists("logs/"):
os.makedirs("logs/")
handler = RotatingFileHandler('logs/main.log', maxBytes=10000000, backupCount=5)
handler.setFormatter(
logging.Formatter('%(asctime)s - %(name)s:{%(pathname)s:%(lineno)d} - %(levelname)s - %(message)s')
)
app.logger.addHandler(handler)
app.logger.setLevel(logging.INFO)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question