From 041547b3173f9e3d3e636a02418c747d2d937275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 3 Dec 2024 21:34:11 +0100 Subject: [PATCH] no longer show prefix --- pkgs/clan-cli/clan_cli/cmd.py | 9 ++++----- pkgs/clan-cli/clan_cli/custom_logger.py | 10 +++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/cmd.py b/pkgs/clan-cli/clan_cli/cmd.py index 5b3cf2d9f..34650d0bc 100644 --- a/pkgs/clan-cli/clan_cli/cmd.py +++ b/pkgs/clan-cli/clan_cli/cmd.py @@ -83,8 +83,10 @@ def handle_io( return b"" # Extra information passed to the logger - stdout_extra = {"command_prefix": prefix} - stderr_extra = {"command_prefix": prefix} + stdout_extra = {} + stderr_extra = {} + if prefix: + stdout_extra["command_prefix"] = stderr_extra["command_prefix"] = prefix if msg_color and msg_color.stderr: stdout_extra["color"] = msg_color.stderr.value if msg_color and msg_color.stdout: @@ -267,9 +269,6 @@ def run( if options.cwd is None: options.cwd = Path.cwd() - if options.prefix is None: - options.prefix = "$" - if options.input: if any(not ch.isprintable() for ch in options.input.decode("ascii", "replace")): filtered_input = "<>" diff --git a/pkgs/clan-cli/clan_cli/custom_logger.py b/pkgs/clan-cli/clan_cli/custom_logger.py index 633c5680f..b56af571a 100644 --- a/pkgs/clan-cli/clan_cli/custom_logger.py +++ b/pkgs/clan-cli/clan_cli/custom_logger.py @@ -25,12 +25,9 @@ class PrefixFormatter(logging.Formatter): print errors in red and warnings in yellow """ - def __init__( - self, trace_prints: bool = False, default_prefix: str | None = None - ) -> None: + def __init__(self, trace_prints: bool = False) -> None: super().__init__() - self.default_prefix = default_prefix self.trace_prints = trace_prints self.hostnames: list[str] = [] self.hostname_color_offset = 0 @@ -51,7 +48,7 @@ class PrefixFormatter(logging.Formatter): msg_color = AnsiColor.DEFAULT.value # If extra["command_prefix"] is set, use that as the logging prefix. - command_prefix = getattr(record, "command_prefix", self.default_prefix) + command_prefix = getattr(record, "command_prefix", None) # If color is disabled, don't use color. if DISABLE_COLOR: @@ -154,7 +151,6 @@ def print_trace(msg: str, logger: logging.Logger, prefix: str | None) -> None: def setup_logging( level: Any, root_log_name: str = __name__.split(".")[0], - default_prefix: str = "clan", ) -> None: # Get the root logger and set its level main_logger = logging.getLogger(root_log_name) @@ -166,5 +162,5 @@ def setup_logging( # Create and add your custom handler default_handler.setLevel(level) trace_prints = bool(int(os.environ.get("TRACE_PRINT", "0"))) - default_handler.setFormatter(PrefixFormatter(trace_prints, default_prefix)) + default_handler.setFormatter(PrefixFormatter(trace_prints)) main_logger.addHandler(default_handler)