Skip to content

Commit

Permalink
fix(logs): Limit log length and check to ensure service is running be…
Browse files Browse the repository at this point in the history
…fore printing logs (#114)

* limit log length and check to ensure service is running before printing logs
  • Loading branch information
hubertdeng123 authored Nov 1, 2024
1 parent 87d7edc commit 363e12a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion devservices/commands/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from argparse import ArgumentParser
from argparse import Namespace

from devservices.constants import MAX_LOG_LINES
from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.utils.docker_compose import run_docker_compose_command
from devservices.utils.services import find_matching_service
from devservices.utils.state import State


def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
Expand Down Expand Up @@ -36,8 +38,16 @@ def logs(args: Namespace) -> None:
mode_to_use = "default"
mode_dependencies = modes[mode_to_use]

state = State()
running_services = state.get_started_services()
if service_name not in running_services:
print(f"Service {service_name} is not running")
return

try:
logs_output = run_docker_compose_command(service, "logs", mode_dependencies)
logs_output = run_docker_compose_command(
service, "logs", mode_dependencies, options=["-n", MAX_LOG_LINES]
)
except DependencyError as de:
print(str(de))
exit(1)
Expand Down
1 change: 1 addition & 0 deletions devservices/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
DOCKER_COMPOSE_DOWNLOAD_URL = "https://github.com/docker/compose/releases/download"
DEVSERVICES_DOWNLOAD_URL = "https://github.com/getsentry/devservices/releases/download"
BINARY_PERMISSIONS = 0o755
MAX_LOG_LINES = "100"

0 comments on commit 363e12a

Please sign in to comment.