Skip to content

Commit

Permalink
Reduce exception info for chadmin output
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgarbar committed Sep 23, 2024
1 parent 0e66e24 commit 456fb2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ch_tools/chadmin/cli/chadmin_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def wrapper(ctx, *a, **kw):
try:
cmd_callback(*a, **kw)
logging.debug("Command '{}' completed", cmd.name)
except Exception:
except Exception as e:
logging.disable_stdout_logger()
logging.exception("Command '{}' failed with error:", cmd.name)
logging.print_last_exception(e)

cmd.callback = wrapper
super().add_command(
Expand Down
8 changes: 8 additions & 0 deletions ch_tools/common/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
WARN,
WARNING,
)
import traceback
from typing import Any, Dict, Optional

from loguru import logger
Expand Down Expand Up @@ -96,6 +97,7 @@ def configure(
"format": format_,
"enqueue": True,
"diagnose": False,
"backtrace": False,
}
if "level" in value:
handler["level"] = value["level"]
Expand Down Expand Up @@ -230,4 +232,10 @@ def enable_stdout_logger():
level="INFO",
format="{message}",
filter=make_filter(logger_config["module"]),
backtrace=False,
diagnose=False,
)


def print_last_exception(e):
traceback.print_exception(BaseException, e, e.__traceback__, chain=False)

0 comments on commit 456fb2c

Please sign in to comment.