Compare commits
1 commit
main
...
log-errors
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa25bd9189 |
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in a new issue