Skip to content

noviicee/logger-python

This branch is 86 commits behind resurfaceio/logger-python:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0d4d68e · May 11, 2021
Jan 29, 2021
Apr 24, 2021
Apr 24, 2021
Jan 26, 2021
Jan 26, 2021
Apr 24, 2021
Feb 2, 2021
Apr 24, 2021
Apr 24, 2021
Jan 18, 2021
Mar 5, 2021
Mar 13, 2021
Feb 5, 2021
Jun 14, 2019
Jan 26, 2021
Mar 2, 2021
Mar 6, 2021
Feb 5, 2021
Feb 9, 2021
Apr 8, 2021
Apr 22, 2021

Repository files navigation

resurfaceio-logger-python

Easily log API requests and responses to your own system of record.

PyPI CodeFactor License Contributing

Contents

Requires Python 3.7 or higher and a requests HTTP library. No other dependencies to conflict with your app.

pip3 install --upgrade usagelogger
from aiohttp import web
from usagelogger.aiohttp import HttpLoggerForAIOHTTP

async def test(request):
    return web.Response(text="Hello")

app = web.Application(
    middlewares=[
        HttpLoggerForAIOHTTP(
            url="http://localhost:4001/message", rules="include debug"
        )
    ]
)
app.router.add_get("/", test)
web.run_app(app)

First edit settings.py to register middleware, like this:

MIDDLEWARE = [
    "django.middleware...",
    "usagelogger.django.HttpLoggerForDjango",
]

Then add a new section to settings.py for logging configuration, like this:

USAGELOGGER = {
    'url': 'http://localhost:4001/message',
    'rules': 'include debug'
}
from flask import Flask
from usagelogger.flask import HttpLoggerForFlask

app = Flask(__name__)

app.wsgi_app = HttpLoggerForFlask(  # type: ignore
    app=app.wsgi_app, url="http://localhost:4001/message", rules="include debug"
)

@app.route("/")
def home():
    return "This route works!"

app.run(debug=True)
from usagelogger import resurface

s = resurface.Session(url="http://localhost:4001/message", rules="include debug")
s.get(...)

Loggers can be directly integrated into your application using our API. This requires the most effort compared with the options described above, but also offers the greatest flexibility and control.

API documentation

Loggers always have an active set of rules that control what data is logged and how sensitive data is masked. All of the examples above apply a predefined set of rules (include debug), but logging rules are easily customized to meet the needs of any application.

Logging rules documentation


© 2016-2021 Resurface Labs Inc.

About

Log API requests and responses with Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.7%
  • Other 0.3%