No project description provided
Project description
FastAPI Error Logger
FastAPI Error Logger is a utility for logging API errors in a FastAPI application. It captures relevant information about the request, such as request body, path parameters, query parameters, headers, and more, and logs this information along with the error details.
Installation
Install the package using pip:
pip install fastapi-error-logger
Function Parameters
The log_api_error function takes the following parameters:
request: FastAPI Request object. status_code: HTTP status code for the error. personalized_message: Optional personalized error message. Make sure to customize the error handling in your FastAPI application according to your requirements.
Usage/Example
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi_error_logger.api_logger import log_api_error
app = FastAPI()
@app.exception_handler(Exception)
async def handle_api_error(request: Request, exc: Exception):
# Log API error using the log_api_error function
await log_api_error(request, status_code=500, personalized_message="An internal server error occurred.")
# Return a custom error response
return JSONResponse(content={"error": "Internal Server Error"}, status_code=500)
@app.get("/")
async def trigger_error():
# Simulate an error for demonstration purposes
raise ValueError("This is a simulated error.")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file fastapi-error-logger-0.1.0.tar.gz
.
File metadata
- Download URL: fastapi-error-logger-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d29118c084bda6fcf8b853df40f8c4e88380a86cd68ec10439744b5f0ae01d07 |
|
MD5 | a3ab96d7889e8014c8c02f2f1d6226e2 |
|
BLAKE2b-256 | 081fd73d6aa7490565f4ade35ab976e16449302599286a88822f3404aaf61076 |
File details
Details for the file fastapi_error_logger-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: fastapi_error_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9da8f02e72b33216e3736bbe3782f2e97baeac1fe165cce170a3354191bf61 |
|
MD5 | c73c05fcb390e16a58cf743a1b224b70 |
|
BLAKE2b-256 | 7d7dee45e3baa3b5067545c33c6dc66fbda5c48756662438b62e29d430e16d7c |