Skip to content

Commit 3dbd68b

Browse files
authored
Fix duplicate server log messages (#3143)
1 parent 8a72c8c commit 3dbd68b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/dstack/_internal/cli/commands/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rich_argparse import RichHelpFormatter
88

99
from dstack._internal.cli.services.completion import ProjectNameCompleter
10+
from dstack._internal.cli.utils.common import configure_logging
1011
from dstack._internal.core.errors import CLIError
1112
from dstack.api import Client
1213

@@ -52,9 +53,16 @@ def _register(self):
5253

5354
@abstractmethod
5455
def _command(self, args: argparse.Namespace):
56+
self._configure_logging()
5557
if not self.ACCEPT_EXTRA_ARGS and args.extra_args:
5658
raise CLIError(f"Unrecognized arguments: {shlex.join(args.extra_args)}")
5759

60+
def _configure_logging(self) -> None:
61+
"""
62+
Override this method to configure command-specific logging
63+
"""
64+
configure_logging()
65+
5866

5967
class APIBaseCommand(BaseCommand):
6068
api: Client

src/dstack/_internal/cli/commands/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ def _command(self, args: argparse.Namespace):
8282
log_level=uvicorn_log_level,
8383
workers=1,
8484
)
85+
86+
def _configure_logging(self) -> None:
87+
# Server logging is configured in the FastAPI lifespan function.
88+
# No need to configure CLI logging.
89+
pass

src/dstack/_internal/cli/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from dstack._internal.cli.commands.stats import StatsCommand
2323
from dstack._internal.cli.commands.stop import StopCommand
2424
from dstack._internal.cli.commands.volume import VolumeCommand
25-
from dstack._internal.cli.utils.common import _colors, configure_logging, console
25+
from dstack._internal.cli.utils.common import _colors, console
2626
from dstack._internal.cli.utils.updates import check_for_updates
2727
from dstack._internal.core.errors import ClientError, CLIError, ConfigurationError, SSHError
2828
from dstack._internal.core.services.ssh.client import get_ssh_client_info
@@ -39,8 +39,6 @@ def main():
3939
RichHelpFormatter.styles["argparse.groups"] = "bold grey74"
4040
RichHelpFormatter.styles["argparse.text"] = "grey74"
4141

42-
configure_logging()
43-
4442
parser = argparse.ArgumentParser(
4543
description=(
4644
"Not sure where to start?"

0 commit comments

Comments
 (0)