Skip to main content

Request lifecycle logger for flask

Project description

OVERVIEW

该工程是 Python 版本的 request-lifecycle,用于收集请求过程中的日志

USAGE

在 Flask 中在请求生命周期的两段嵌入如下代码。在嵌入 before_request 后,可以通过 g.trace_id 获取请求的 ID。

from flask import Flask
from request_lifecycle import RequestLifecycleMiddleware


app = Flask(__name__)


@app.before_request
def before_request():
    """在这里放入一个配置好 log-server 的前置中间件
    """
    RequestLifecycleMiddleware.before_request(host='127.0.0.1', port='3000', app_name='whatever',
                                              additional_req_fields=[])


@app.after_request
def after_request(response: Flask.response_class):
    """在这里放入一个捕捉 response 的中间件
    """
    additional_message = { 'adminTraceId': 'traceId' }
    RequestLifecycleMiddleware.after_request(response=response, additional_log_message=additional_message)
    return response

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

request_lifecycle-1.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

request_lifecycle-1.1.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file request_lifecycle-1.1.3.tar.gz.

File metadata

  • Download URL: request_lifecycle-1.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for request_lifecycle-1.1.3.tar.gz
Algorithm Hash digest
SHA256 eb654fe8a8d1b30951737c7b898d709fec11b8faaba9832e5ccc21c397111379
MD5 43a29a8d07fdf98f92f45b6f09bac876
BLAKE2b-256 34519b715da0a1a3d20c9077dfe1190cf6832f584eadc31275c4f7c73d3c9f87

See more details on using hashes here.

File details

Details for the file request_lifecycle-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: request_lifecycle-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for request_lifecycle-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fc4fa42cc0a13a6a6cd5030ce6f096651c3ac78da8bbd27817c67b27b93acc1b
MD5 5009d92ad925cd12cf3f6e2435ecb118
BLAKE2b-256 9fb508bad552cc2d5ddd88db79b3b696f98bae724984e441825e16e4bbb4d8ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page