Compare commits

...

1 commit

Author SHA1 Message Date
Csaba aa25bd9189 Log errors to file
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
2024-02-29 12:28:18 +01:00
2 changed files with 15 additions and 3 deletions

View file

@ -13,7 +13,9 @@ copy_static_files(["conf", "static", "templates", "logging.conf", "config"])
import amarillo.plugins
from amarillo.configuration import configure_services, configure_admin_token
from amarillo.routers import carpool, agency, agencyconf, region
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
import traceback
# https://pydantic-docs.helpmanual.io/usage/settings/
from amarillo.views import home
@ -87,6 +89,10 @@ app.include_router(agency.router)
app.include_router(agencyconf.router)
app.include_router(region.router)
@app.exception_handler(Exception)
async def log_exception(request, exc):
logger.error(f"500 Error: {exc} \n{traceback.format_exc()}")
return JSONResponse(status_code=500, content={"message": "Internal Server Error"})
def iter_namespace(ns_pkg):
# Source: https://packaging.python.org/guides/creating-and-discovering-plugins/

View file

@ -2,14 +2,14 @@
keys=root
[handlers]
keys=consoleHandler
keys=consoleHandler, fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=INFO
handlers=consoleHandler
handlers=consoleHandler, fileHandler
propagate=yes
[handler_consoleHandler]
@ -18,5 +18,11 @@ level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=handlers.RotatingFileHandler
level=ERROR
formatter=simpleFormatter
args=('error.log', 'a', 1000000, 3) # Filename, mode, maxBytes, backupCount
[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s