disable fastapi access logs

This commit is contained in:
Dinesh Yeduguru 2024-12-06 11:25:53 -08:00
parent 208cded50e
commit 83de0c7995
2 changed files with 8 additions and 6 deletions

View file

@ -347,7 +347,7 @@ def main():
listen_host = ["::", "0.0.0.0"] if not args.disable_ipv6 else "0.0.0.0" listen_host = ["::", "0.0.0.0"] if not args.disable_ipv6 else "0.0.0.0"
print(f"Listening on {listen_host}:{args.port}") print(f"Listening on {listen_host}:{args.port}")
uvicorn.run(app, host=listen_host, port=args.port) uvicorn.run(app, host=listen_host, port=args.port, access_log=False)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -39,7 +39,9 @@ class ConsoleSpanProcessor(SpanProcessor):
)[:-3] )[:-3]
print( print(
f"{COLORS['dim']}{timestamp} " f"[START] " f"{span.name}{COLORS['reset']}" f"{timestamp} "
f"{COLORS['bold']}[START]{COLORS['reset']} "
f"{COLORS['dim']}{span.name}{COLORS['reset']}"
) )
def on_end(self, span: ReadableSpan) -> None: def on_end(self, span: ReadableSpan) -> None:
@ -50,15 +52,15 @@ class ConsoleSpanProcessor(SpanProcessor):
"%H:%M:%S.%f" "%H:%M:%S.%f"
)[:-3] )[:-3]
span_context = f"{COLORS['dim']}{timestamp} [END] {span.name}" span_context = f"{timestamp} {COLORS['bold']}[END]{COLORS['reset']} {COLORS['dim']}{span.name}"
if span.status.status_code == 2: # ERROR if span.status.status_code == 2: # ERROR
span_context += f" {COLORS['red']}[ERROR]{COLORS['reset']}" span_context += f"{COLORS['reset']} {COLORS['red']}[ERROR]{COLORS['reset']}"
elif span.status.status_code != 0: # UNSET elif span.status.status_code != 0: # UNSET
span_context += f" {COLORS['dim']}[{span.status.status_code}]" span_context += f"{COLORS['reset']} [{span.status.status_code}]"
duration_ms = (span.end_time - span.start_time) / 1e6 duration_ms = (span.end_time - span.start_time) / 1e6
span_context += f" ({duration_ms:.2f}ms){COLORS['reset']}" span_context += f"{COLORS['reset']} ({duration_ms:.2f}ms)"
print(span_context) print(span_context)