FastAPI MongoDB logging package for endpoints and general logging
Project description
FastAPI MongoDB Logger
A comprehensive logging package for FastAPI applications that stores endpoint logs and custom events in MongoDB.
Installation
pip install fastapi-mongo-logger-mateoramos
Quick Start
1. Basic Setup
from fastapi import FastAPI
from fastapi_mongo_logger import MongoLogger, LoggingMiddleware
app = FastAPI()
# Initialize logger
logger = MongoLogger(
mongo_url="mongodb://localhost:27017",
database_name="my_app_logs",
collection_name="api_logs"
)
# Add middleware for automatic endpoint logging
app.add_middleware(LoggingMiddleware, logger=logger)
@app.get("/")
async def root():
return {"message": "Hello World"}
2. Manual Logging with Decorators
from fastapi_mongo_logger import log_endpoint, log_function
@log_endpoint(logger, user_type="admin")
async def admin_function():
# Your code here
pass
@log_function(logger, event_type="data_processing")
def process_data():
# Your code here
pass
3. Custom Logging
# Log custom events anywhere in your code
await logger.log_custom("user_action", {
"user_id": "123",
"action": "login",
"ip_address": "192.168.1.1"
})
Features
- Automatic endpoint logging via middleware
- Manual logging with decorators
- Custom event logging for any part of your application
- Comprehensive data capture: request/response bodies, headers, timing, errors
- Async/sync function support
- Flexible data storage in MongoDB
Configuration Options
log_request_body: Enable/disable request body logging (default: True)log_response_body: Enable/disable response body logging (default: False)- Custom fields can be added to any log entry
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_mongo_logger_mateoramos-1.0.6.tar.gz.
File metadata
- Download URL: fastapi_mongo_logger_mateoramos-1.0.6.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
263aeefa143261087c44953e5a3acd05c5b002ab7e245eff6ddcf34186197da0
|
|
| MD5 |
ec6da60a15c9f052cde25ae41165014c
|
|
| BLAKE2b-256 |
6c229c6b3266824a67dd558523abe71a49aa6e5ad8d8aaff8cf4923d3067bac9
|
Provenance
The following attestation bundles were made for fastapi_mongo_logger_mateoramos-1.0.6.tar.gz:
Publisher:
release.yaml on mateoramos97/fastapi-mongo-logs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_mongo_logger_mateoramos-1.0.6.tar.gz -
Subject digest:
263aeefa143261087c44953e5a3acd05c5b002ab7e245eff6ddcf34186197da0 - Sigstore transparency entry: 752450723
- Sigstore integration time:
-
Permalink:
mateoramos97/fastapi-mongo-logs@ccb2dc3d27c4d1f44c3ddbed2298c3dcb5dce5dd -
Branch / Tag:
refs/tags/1.0.6 - Owner: https://github.com/mateoramos97
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ccb2dc3d27c4d1f44c3ddbed2298c3dcb5dce5dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_mongo_logger_mateoramos-1.0.6-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_logger_mateoramos-1.0.6-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe34c82b3e6b83dbb3a2e634cbfff1b6fb74108e0dfb72416b589d4fd80f6120
|
|
| MD5 |
3eb982ca5bfc57302cf7e3f7e91dba17
|
|
| BLAKE2b-256 |
d37bedea7a262f113461cf928073d61597fc94aeacec682fcf2c848613927c85
|
Provenance
The following attestation bundles were made for fastapi_mongo_logger_mateoramos-1.0.6-py3-none-any.whl:
Publisher:
release.yaml on mateoramos97/fastapi-mongo-logs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_mongo_logger_mateoramos-1.0.6-py3-none-any.whl -
Subject digest:
fe34c82b3e6b83dbb3a2e634cbfff1b6fb74108e0dfb72416b589d4fd80f6120 - Sigstore transparency entry: 752450728
- Sigstore integration time:
-
Permalink:
mateoramos97/fastapi-mongo-logs@ccb2dc3d27c4d1f44c3ddbed2298c3dcb5dce5dd -
Branch / Tag:
refs/tags/1.0.6 - Owner: https://github.com/mateoramos97
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ccb2dc3d27c4d1f44c3ddbed2298c3dcb5dce5dd -
Trigger Event:
push
-
Statement type: