Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-error-logger-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

fastapi_error_logger-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-error-logger-0.0.1.tar.gz.

File metadata

  • Download URL: fastapi-error-logger-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for fastapi-error-logger-0.0.1.tar.gz
Algorithm Hash digest
SHA256 df5ad71390df880878185e2e1c1bb2beeef5ddf1bee199314bdd3da9950146df
MD5 9b8ef9b7674a60e3341035a96fa8a7f8
BLAKE2b-256 9b4eef2149d60131c21254c6f09ec1ac849bc784b0406b83da1ac15fbda43ad1

See more details on using hashes here.

File details

Details for the file fastapi_error_logger-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_error_logger-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2297f950d54cf989025aa4e395fd8bd05ba83db987d1439f3998ff3d66446539
MD5 087c6c21d09058a112d467af994ab4b7
BLAKE2b-256 548a54eacef75bffbbe9d0a5f1fa9128fb9e13ad1609af74c2088733b5068d33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page