From 15f0ac30b5067a2694ddb8dca9c730d33714d12b Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:12:54 +0100 Subject: [PATCH] "kiwi logs" --- kiwi_scp/commands/cmd_logs.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 kiwi_scp/commands/cmd_logs.py diff --git a/kiwi_scp/commands/cmd_logs.py b/kiwi_scp/commands/cmd_logs.py new file mode 100644 index 0000000..f31a066 --- /dev/null +++ b/kiwi_scp/commands/cmd_logs.py @@ -0,0 +1,42 @@ +from typing import List + +import click + +from .cli import KiwiCommand, KiwiCommandType +from .decorators import kiwi_command +from ..executable import COMPOSE_EXE +from ..instance import Instance, Project, Services + + +@click.option( + "-f/-F", + "--follow/--no-follow", + help="output appended data as log grows", +) +@kiwi_command( + short_help="Show logs", +) +class LogsCommand(KiwiCommand): + """Show logs of a project or service(s) inside a project""" + + type = KiwiCommandType.SERVICES + enabled_only = True + + @classmethod + def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services, + new_service_names: List[str], follow: bool = None) -> None: + # include timestamps + compose_cmd = ["logs", "-t"] + + # handle following the log output + if follow: + compose_cmd.extend(("-f", "--tail=10")) + + compose_cmd.extend(services.names) + + if follow: + COMPOSE_EXE.run(compose_cmd, **project.process_kwargs) + + else: + # output is static, use pager + COMPOSE_EXE.run_with_pager(compose_cmd, **project.process_kwargs)