Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ml): error logging #6646

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions machine-learning/app/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import concurrent.futures
import logging
import os
import sys
from pathlib import Path
from socket import socket

import starlette
from gunicorn.arbiter import Arbiter
from pydantic import BaseSettings
from rich.console import Console
Expand Down Expand Up @@ -74,10 +74,28 @@ def get_hf_model_name(model_name: str) -> str:
class CustomRichHandler(RichHandler):
def __init__(self) -> None:
console = Console(color_system="standard", no_color=log_settings.no_color)
super().__init__(show_path=False, omit_repeated_times=False, console=console, tracebacks_suppress=[starlette])


log = logging.getLogger("gunicorn.access")
self.excluded = ["uvicorn", "starlette", "fastapi"]
super().__init__(
show_path=False,
omit_repeated_times=False,
console=console,
rich_tracebacks=True,
tracebacks_suppress=[*self.excluded, concurrent.futures],
)

# hack to exclude certain modules from rich tracebacks
def emit(self, record: logging.LogRecord) -> None:
if record.exc_info is not None:
tb = record.exc_info[2]
while tb is not None:
if any(excluded in tb.tb_frame.f_code.co_filename for excluded in self.excluded):
tb.tb_frame.f_locals["_rich_traceback_omit"] = True
tb = tb.tb_next

return super().emit(record)


log = logging.getLogger("ml.log")
log.setLevel(LOG_LEVELS.get(log_settings.log_level.lower(), logging.INFO))


Expand Down
11 changes: 5 additions & 6 deletions machine-learning/log_conf.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"version": 1,
"disable_existing_loggers": true,
"formatters": { "rich": { "show_path": false, "omit_repeated_times": false } },
"disable_existing_loggers": false,
"handlers": {
"console": {
"class": "app.config.CustomRichHandler",
"formatter": "rich"
"class": "app.config.CustomRichHandler"
}
},
"loggers": {
"gunicorn.access": { "propagate": true },
"gunicorn.error": { "propagate": true }
"gunicorn.error": {
"handlers": ["console"]
}
},
"root": { "handlers": ["console"] }
}
Loading