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.2.tar.gz
.
File metadata
- Download URL: fastapi-error-logger-0.1.2.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 | 3192609de0d6f3c2c68d7436aff9f2f05ba689968ab4582e92695ed53bf9734d |
|
MD5 | d5d914eaa3e44bcd97f21255782a4df4 |
|
BLAKE2b-256 | d0373de9106077546c16e3725db9fc58f6740e68075886f59fd0084121b967ca |
File details
Details for the file fastapi_error_logger-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_error_logger-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.4 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 | 909f2899903403e275c112416186315fd72a2c7952e59c0284a86212c52562ab |
|
MD5 | 22c7ff044ad925816529c9ca25c5c545 |
|
BLAKE2b-256 | ec71bfd44c3397a24fa9e302d629df9963eb04c7c95099f8cb7d498391a6ed0c |