log all incoming requests
This commit is contained in:
parent
1c3d745a1a
commit
7d23b15043
@ -1,7 +1,9 @@
|
|||||||
"""create_app application factory function and similar things."""
|
"""create_app application factory function and similar things."""
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from logging.config import dictConfig
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask, request
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
@ -18,6 +20,15 @@ def create_app(test_config=None):
|
|||||||
else:
|
else:
|
||||||
app.config.from_mapping(test_config)
|
app.config.from_mapping(test_config)
|
||||||
|
|
||||||
|
print(app.config['LOGGING'])
|
||||||
|
dictConfig(app.config['LOGGING'])
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def log_request():
|
||||||
|
logger.info("REQUEST: [ %s ]", request.path)
|
||||||
|
|
||||||
from . import journal
|
from . import journal
|
||||||
app.register_blueprint(journal.bp)
|
app.register_blueprint(journal.bp)
|
||||||
|
|
||||||
|
@ -9,3 +9,25 @@ class Config(object):
|
|||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
TESTING = False
|
TESTING = False
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'formatters': {
|
||||||
|
'default': {
|
||||||
|
'format': '[%(asctime)s %(levelname)-7s %(name)s] %(message)s',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'default',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'handlers': ['console'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user