Log errors to file
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
This commit is contained in:
parent
c521fe5a9a
commit
aa25bd9189
|
|
@ -13,7 +13,9 @@ copy_static_files(["conf", "static", "templates", "logging.conf", "config"])
|
||||||
import amarillo.plugins
|
import amarillo.plugins
|
||||||
from amarillo.configuration import configure_services, configure_admin_token
|
from amarillo.configuration import configure_services, configure_admin_token
|
||||||
from amarillo.routers import carpool, agency, agencyconf, region
|
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/
|
# https://pydantic-docs.helpmanual.io/usage/settings/
|
||||||
from amarillo.views import home
|
from amarillo.views import home
|
||||||
|
|
@ -87,6 +89,10 @@ app.include_router(agency.router)
|
||||||
app.include_router(agencyconf.router)
|
app.include_router(agencyconf.router)
|
||||||
app.include_router(region.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):
|
def iter_namespace(ns_pkg):
|
||||||
# Source: https://packaging.python.org/guides/creating-and-discovering-plugins/
|
# Source: https://packaging.python.org/guides/creating-and-discovering-plugins/
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
keys=root
|
keys=root
|
||||||
|
|
||||||
[handlers]
|
[handlers]
|
||||||
keys=consoleHandler
|
keys=consoleHandler, fileHandler
|
||||||
|
|
||||||
[formatters]
|
[formatters]
|
||||||
keys=simpleFormatter
|
keys=simpleFormatter
|
||||||
|
|
||||||
[logger_root]
|
[logger_root]
|
||||||
level=INFO
|
level=INFO
|
||||||
handlers=consoleHandler
|
handlers=consoleHandler, fileHandler
|
||||||
propagate=yes
|
propagate=yes
|
||||||
|
|
||||||
[handler_consoleHandler]
|
[handler_consoleHandler]
|
||||||
|
|
@ -18,5 +18,11 @@ level=DEBUG
|
||||||
formatter=simpleFormatter
|
formatter=simpleFormatter
|
||||||
args=(sys.stdout,)
|
args=(sys.stdout,)
|
||||||
|
|
||||||
|
[handler_fileHandler]
|
||||||
|
class=handlers.RotatingFileHandler
|
||||||
|
level=ERROR
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=('error.log', 'a', 1000000, 3) # Filename, mode, maxBytes, backupCount
|
||||||
|
|
||||||
[formatter_simpleFormatter]
|
[formatter_simpleFormatter]
|
||||||
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
Loading…
Reference in a new issue