Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sgykfjsm/flask-logging-decorator
a deadly simple logging decorator for Flask
https://github.com/sgykfjsm/flask-logging-decorator
decorator flask logging python
Last synced: 10 days ago
JSON representation
a deadly simple logging decorator for Flask
- Host: GitHub
- URL: https://github.com/sgykfjsm/flask-logging-decorator
- Owner: sgykfjsm
- Created: 2018-05-18T01:51:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T17:28:20.000Z (over 3 years ago)
- Last Synced: 2024-10-11T10:08:16.351Z (27 days ago)
- Topics: decorator, flask, logging, python
- Language: Python
- Size: 31.3 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# flask-logging-decorator
[![Build Status](https://travis-ci.org/sgykfjsm/flask-logging-decorator.svg?branch=master)](https://travis-ci.org/sgykfjsm/flask-logging-decorator)
This is a deadly simple logging decorator for Flask. This is highly inspired by [canassa/flask-trace](https://github.com/canassa/flask-trace).
## Compatibility
This is tested with Python3.5, 3.6 and Flask1.0.2.
## Installation
```bash
pip install flask-logging-decorator
```## Run the test
This modules uses [pytest](http://pytest.org/latest/). You can install it before running the test.
```bash
python -m pytest -v
```## Usage
Import and put it as the decorator function.
```python
import loggingfrom flask_logging_decorator import trace
from flask import Flaskapp = Flask(__name__)
@trace(logging.ERROR)
@app.route('/')
def index():
return 'hello'...
```The application should show the logging message like following.
```text
[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
```If you don't pass the logging level to `@trace`, it will use the Flask's application logger.
## License
MIT license, see the LICENSE file. You can use this library in open source projects and commercial products.