diff --git a/src/dstack/_internal/cli/commands/__init__.py b/src/dstack/_internal/cli/commands/__init__.py index da89156e5..b1a56b92e 100644 --- a/src/dstack/_internal/cli/commands/__init__.py +++ b/src/dstack/_internal/cli/commands/__init__.py @@ -7,6 +7,7 @@ from rich_argparse import RichHelpFormatter from dstack._internal.cli.services.completion import ProjectNameCompleter +from dstack._internal.cli.utils.common import configure_logging from dstack._internal.core.errors import CLIError from dstack.api import Client @@ -52,9 +53,16 @@ def _register(self): @abstractmethod def _command(self, args: argparse.Namespace): + self._configure_logging() if not self.ACCEPT_EXTRA_ARGS and args.extra_args: raise CLIError(f"Unrecognized arguments: {shlex.join(args.extra_args)}") + def _configure_logging(self) -> None: + """ + Override this method to configure command-specific logging + """ + configure_logging() + class APIBaseCommand(BaseCommand): api: Client diff --git a/src/dstack/_internal/cli/commands/server.py b/src/dstack/_internal/cli/commands/server.py index ebbc8a1bc..c233634f3 100644 --- a/src/dstack/_internal/cli/commands/server.py +++ b/src/dstack/_internal/cli/commands/server.py @@ -82,3 +82,8 @@ def _command(self, args: argparse.Namespace): log_level=uvicorn_log_level, workers=1, ) + + def _configure_logging(self) -> None: + # Server logging is configured in the FastAPI lifespan function. + # No need to configure CLI logging. + pass diff --git a/src/dstack/_internal/cli/main.py b/src/dstack/_internal/cli/main.py index eb39fd195..2ef297905 100644 --- a/src/dstack/_internal/cli/main.py +++ b/src/dstack/_internal/cli/main.py @@ -22,7 +22,7 @@ from dstack._internal.cli.commands.stats import StatsCommand from dstack._internal.cli.commands.stop import StopCommand from dstack._internal.cli.commands.volume import VolumeCommand -from dstack._internal.cli.utils.common import _colors, configure_logging, console +from dstack._internal.cli.utils.common import _colors, console from dstack._internal.cli.utils.updates import check_for_updates from dstack._internal.core.errors import ClientError, CLIError, ConfigurationError, SSHError from dstack._internal.core.services.ssh.client import get_ssh_client_info @@ -39,8 +39,6 @@ def main(): RichHelpFormatter.styles["argparse.groups"] = "bold grey74" RichHelpFormatter.styles["argparse.text"] = "grey74" - configure_logging() - parser = argparse.ArgumentParser( description=( "Not sure where to start?"