[debug] added /halfapi/log as a debug route that generates all type of logs
This commit is contained in:
parent
d4a6bb1a04
commit
f4ba64f186
|
@ -9,6 +9,8 @@ It defines the following globals :
|
||||||
- application (the asgi application itself - a starlette object)
|
- application (the asgi application itself - a starlette object)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
# asgi framework
|
# asgi framework
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
from starlette.authentication import UnauthenticatedUser
|
from starlette.authentication import UnauthenticatedUser
|
||||||
|
@ -27,9 +29,10 @@ from halfapi.lib.jwt_middleware import JWTAuthenticationBackend
|
||||||
from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse,
|
from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse,
|
||||||
NotFoundResponse, InternalServerErrorResponse, NotImplementedResponse)
|
NotFoundResponse, InternalServerErrorResponse, NotImplementedResponse)
|
||||||
|
|
||||||
from halfapi.lib.routes import gen_starlette_routes, api_routes
|
from halfapi.lib.routes import gen_starlette_routes, api_routes, debug_routes
|
||||||
from halfapi.lib.schemas import get_api_routes, schema_json, get_acls
|
from halfapi.lib.schemas import get_api_routes, schema_json, get_acls
|
||||||
|
|
||||||
|
logger = logging.getLogger('uvicorn.asgi')
|
||||||
|
|
||||||
routes = [ Route('/', get_api_routes) ]
|
routes = [ Route('/', get_api_routes) ]
|
||||||
|
|
||||||
|
@ -43,6 +46,10 @@ routes += [
|
||||||
Route('/halfapi/acls', get_acls)
|
Route('/halfapi/acls', get_acls)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not PRODUCTION:
|
||||||
|
for route in debug_routes():
|
||||||
|
routes.append( route )
|
||||||
|
|
||||||
|
|
||||||
for route in gen_starlette_routes(DOMAINSDICT()):
|
for route in gen_starlette_routes(DOMAINSDICT()):
|
||||||
routes.append(route)
|
routes.append(route)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
from datetime import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List, Dict, Generator
|
from typing import Callable, List, Dict, Generator
|
||||||
|
@ -7,6 +8,7 @@ from types import ModuleType, FunctionType
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.routing import Route
|
from starlette.routing import Route
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
from starlette.responses import Response
|
||||||
|
|
||||||
from halfapi.lib.domain import gen_domain_routes, VERBS
|
from halfapi.lib.domain import gen_domain_routes, VERBS
|
||||||
|
|
||||||
|
@ -140,3 +142,14 @@ def api_acls(request):
|
||||||
res[domain][acl_name] = fct_result
|
res[domain][acl_name] = fct_result
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def debug_routes():
|
||||||
|
async def debug_log(request: Request, *args, **kwargs):
|
||||||
|
logger.debug('debuglog# %s', {datetime.now().isoformat()})
|
||||||
|
logger.info('debuglog# %s', {datetime.now().isoformat()})
|
||||||
|
logger.warning('debuglog# %s', {datetime.now().isoformat()})
|
||||||
|
logger.error('debuglog# %s', {datetime.now().isoformat()})
|
||||||
|
logger.critical('debuglog# %s', {datetime.now().isoformat()})
|
||||||
|
return Response('')
|
||||||
|
yield Route('/halfapi/log', debug_log)
|
||||||
|
|
Loading…
Reference in New Issue