Simple logging decorator for Flask.
Project description
flask-logging-decorator
This is a deadly simple logging decorator for Flask. This is highly inspired by canassa/flask-trace.
Compatibility
This is tested with Python3.6.5 and Flask1.0.2.
Installation
pip install flask-logging-decorator
Run the test
This modules uses pytest. You can install it before running the test.
python -m pytest -v
Usage
Import and put it as the decorator function.
import logging
from flask_logging_decorator import trace
from flask import Flask
app = Flask(__name__)
@trace(logging.ERROR)
@app.route('/')
def index():
return 'hello'
...
The application should show the logging message like following.
[2018-05-17 19:01:31,468] ERROR in __init__: trace_uuid=cf66d343-06f4-49cb-a680-59ba9ec77570 method=GET func_name=index func_args: query_args:foo='bar' baz='qux' post_values: trace_info:trace_pathname=main.py trace_lineno=12
Note that don't forget to pass the log level argument. You have to pass the appropriate logging level. Otherwise, this decorator never output any messages.
License
MIT license, see the LICENSE file. You can use this library in open source projects and commercial products.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_logging_decorator-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d223efc942e4d744e197eb915638bb6f4836fdb554b76fef1b354f0aa84d5fc |
|
MD5 | 1f44338077e0a6f0150f86e2b29bdfc6 |
|
BLAKE2b-256 | 719df31d2622b53795fd24371dbc850bfb6606323673d5c63ea7e1a53c4f71c9 |
Hashes for flask_logging_decorator-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f134575339f4e66b34ae6ed3a0d73086582d18b71a1740ffa241ae734bdf714 |
|
MD5 | 1386cf48ba00616797f8922d980be136 |
|
BLAKE2b-256 | 58ba6420e35a23302370d8c75058b77d33ad2511cd911421deae8a56be0a9232 |