# app/__init__.py
import logging
def create_app():
app = Flask(__name__)
app.logger.setLevel(logging.INFO)
....
return app
# app/__init__.py
import logging
def create_app():
....
logger = logging.getLogger("app.module_one")
logger.setLevel(logging.ERROR)
....
return app
INFO:werkzeug:127.0.0.1 - - [13/Dec/2017 00:26:15] "GET /index/ HTTP/1.1" 200 -
# app/module_one/controllers.py
@module.route('/index/')
def index():
....
logging.basicConfig(level=logging.INFO)
logging.info('My message')
....
# config.py
class Config(object):
TESTING = False
# И еще конфиги разные
class ProductionConfig(Config):
DEBUG = False
LOGFILE = 'logs/Production.log'
class DevelopmentConfig(Config):
DEBUG = True
LOGFILE = 'logs/Development.log'
# app.py
from logging.handlers import RotatingFileHandler
from logging import Formatter
import logging
app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')
# -----------------------------------------------------------------------------
# Включение, отключение и ротация логов.
# -----------------------------------------------------------------------------
handler = RotatingFileHandler(app.config['LOGFILE'],
maxBytes=1000000, backupCount=1)
handler.setLevel(logging.DEBUG)
handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'))
# logging.disable(logging.CRITICAL) # Расскоментарь это для прекращения логов
app.logger.addHandler(handler)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
app.logger.info("My message")
return 'Hello, World!'
if __name__ == "__main__":
app.run(debug=True)