Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logs): Limit log length and check to ensure service is running before printing logs #114

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion devservices/commands/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 +37,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")
exit(0)

try:
logs_output = run_docker_compose_command(service, "logs", mode_dependencies)
logs_output = run_docker_compose_command(
service, "logs", mode_dependencies, options=["-n", "100"]
)
except DependencyError as de:
print(str(de))
exit(1)
Expand Down