aboutsummaryrefslogtreecommitdiff
path: root/modules/api
diff options
context:
space:
mode:
authorVladimir Mandic <mandic00@live.com>2023-01-03 10:58:52 -0500
committerGitHub <noreply@github.com>2023-01-03 10:58:52 -0500
commitcec209981ee988536c2521297baf9bc1b256005f (patch)
tree85cad56f468663d5ffe94dab8e3eab2d33125d7f /modules/api
parentaaa4c2aacbb6523077334093c81bd475d757f7a1 (diff)
log only sdapi
Diffstat (limited to 'modules/api')
-rw-r--r--modules/api/api.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/api/api.py b/modules/api/api.py
index 53135470..78751c57 100644
--- a/modules/api/api.py
+++ b/modules/api/api.py
@@ -68,22 +68,23 @@ def encode_pil_to_base64(image):
bytes_data = output_bytes.getvalue()
return base64.b64encode(bytes_data)
-def init_api_middleware(app: FastAPI):
+def api_middleware(app: FastAPI):
@app.middleware("http")
async def log_and_time(req: Request, call_next):
ts = time.time()
res: Response = await call_next(req)
duration = str(round(time.time() - ts, 4))
res.headers["X-Process-Time"] = duration
- if shared.cmd_opts.api_log:
- print('API {t} {code} {prot}/{ver} {method} {p} {cli} {duration}'.format(
+ endpoint = req.scope.get('path', 'err')
+ if shared.cmd_opts.api_log and endpoint.startswith('/sdapi'):
+ print('API {t} {code} {prot}/{ver} {method} {endpoint} {cli} {duration}'.format(
t = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"),
code = res.status_code,
ver = req.scope.get('http_version', '0.0'),
cli = req.scope.get('client', ('0:0.0.0', 0))[0],
prot = req.scope.get('scheme', 'err'),
method = req.scope.get('method', 'err'),
- p = req.scope.get('path', 'err'),
+ endpoint = endpoint,
duration = duration,
))
return res