Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/resurfaceio/logger-python
Log API calls with Python
https://github.com/resurfaceio/logger-python
aiohttp api-logger django flask http-logger logger-python python requests-module
Last synced: 14 days ago
JSON representation
Log API calls with Python
- Host: GitHub
- URL: https://github.com/resurfaceio/logger-python
- Owner: resurfaceio
- License: apache-2.0
- Created: 2019-05-31T19:47:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-08T14:35:07.000Z (12 months ago)
- Last Synced: 2024-04-26T20:07:41.448Z (8 months ago)
- Topics: aiohttp, api-logger, django, flask, http-logger, logger-python, python, requests-module
- Language: Python
- Homepage:
- Size: 2.83 MB
- Stars: 22
- Watchers: 5
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# resurfaceio-logger-python
Easily log API requests and responses to your own security data lake.[![PyPI](https://img.shields.io/pypi/v/usagelogger)](https://badge.fury.io/py/usagelogger)
[![CodeFactor](https://www.codefactor.io/repository/github/resurfaceio/logger-python/badge)](https://www.codefactor.io/repository/github/resurfaceio/logger-python)
[![License](https://img.shields.io/github/license/resurfaceio/logger-python)](https://github.com/resurfaceio/logger-python/blob/master/LICENSE)
[![Contributing](https://img.shields.io/badge/contributions-welcome-green.svg)](https://github.com/resurfaceio/logger-python/blob/master/CONTRIBUTING.md)## Contents
- Dependencies
- Installing With pip
- Logging From AIOHTTP
- Logging From Django
- Logging From Flask
- Logging From Requests
- Logging With API
- Protecting User Privacy
## Dependencies
Requires Python 3.7 or higher and a `requests` HTTP library. No other dependencies to conflict with your app.
## Installing With pip
```
pip3 install --upgrade usagelogger
```
## Logging From AIOHTTP
```python
from aiohttp import web
from usagelogger.middleware.aiohttp import HttpLoggerForAIOHTTP
async def test(request):
return web.Response(text="Hello")
app = web.Application(
middlewares=[
HttpLoggerForAIOHTTP(
url="http://localhost:7701/message", rules="include debug"
)
]
)
app.router.add_get("/", test)
web.run_app(app)
```
## Logging From Django
First edit `settings.py` to register middleware, like this:
*Note: We recommend placing Resurface middleware at the top in the middleware stack.*
```python
MIDDLEWARE = [
"usagelogger.middleware.django.HttpLoggerForDjango", # Always on the top
"django.middleware...",
]
```
Then add a new section to `settings.py` for logging configuration, like this:
```python
USAGELOGGER = {
'url': 'http://localhost:7701/message',
'rules': 'include debug'
}
```
## Logging From Flask
```python
from flask import Flask
from usagelogger.middleware.flask import HttpLoggerForFlask
app = Flask(__name__)
app.wsgi_app = HttpLoggerForFlask( # type: ignore
app=app.wsgi_app, url="http://localhost:7701/message", rules="include debug"
)
@app.route("/")
def home():
return "This route works!"
app.run(debug=True)
```
## Logging From Requests
```python
from usagelogger import resurface
s = resurface.Session(url="http://localhost:7701/message", rules="include debug")
s.get(...)
```
## Logging With API
Loggers can be directly integrated into your application using our [API](API.md). This requires the most effort compared with
the options described above, but also offers the greatest flexibility and control.
[API documentation](API.md)
## Protecting User Privacy
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.
---
© 2016-2024 Graylog, Inc.