2020-08-12 15:46:50 +00:00
|
|
|
# local
|
2020-08-19 15:21:38 +00:00
|
|
|
from ..subcommand import ServiceCommand
|
2020-08-08 17:41:11 +00:00
|
|
|
|
|
|
|
|
2020-08-13 09:32:54 +00:00
|
|
|
class LogsCommand(ServiceCommand):
|
2020-08-17 08:08:29 +00:00
|
|
|
"""kiwi logs"""
|
|
|
|
|
2020-08-10 13:48:15 +00:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
2020-08-17 10:58:18 +00:00
|
|
|
'logs', num_projects=1, num_services='*',
|
2020-08-19 14:10:56 +00:00
|
|
|
action="Showing logs of",
|
2020-08-20 12:40:49 +00:00
|
|
|
description="Show logs of a project or service(s) inside a project"
|
2020-08-10 14:36:05 +00:00
|
|
|
)
|
|
|
|
|
2020-08-13 09:32:54 +00:00
|
|
|
# -f switch: Follow logs
|
2020-08-11 12:03:00 +00:00
|
|
|
self._sub_parser.add_argument(
|
2020-08-10 15:40:56 +00:00
|
|
|
'-f', '--follow', action='store_true',
|
2020-08-10 14:36:05 +00:00
|
|
|
help="output appended data as log grows"
|
2020-08-10 09:24:39 +00:00
|
|
|
)
|
2020-08-08 17:41:11 +00:00
|
|
|
|
2020-08-19 14:10:56 +00:00
|
|
|
def _run_services(self, runner, args, project, services):
|
2020-08-13 12:26:49 +00:00
|
|
|
# include timestamps
|
|
|
|
compose_cmd = ['logs', '-t']
|
|
|
|
|
|
|
|
# handle following the log output
|
2020-08-11 12:03:00 +00:00
|
|
|
if args.follow:
|
2020-08-13 12:26:49 +00:00
|
|
|
compose_cmd = [*compose_cmd, '-f', '--tail=10']
|
2020-08-10 14:36:05 +00:00
|
|
|
|
2020-08-13 12:26:49 +00:00
|
|
|
# append if one or more services are given
|
2020-08-19 14:10:56 +00:00
|
|
|
if services:
|
2020-08-13 12:26:49 +00:00
|
|
|
compose_cmd = [*compose_cmd, *args.services]
|
2020-08-13 09:34:30 +00:00
|
|
|
|
2020-08-13 12:26:49 +00:00
|
|
|
if args.follow:
|
2020-08-19 15:09:43 +00:00
|
|
|
project.compose_run(compose_cmd)
|
|
|
|
|
2020-08-13 12:26:49 +00:00
|
|
|
else:
|
2020-08-19 15:09:43 +00:00
|
|
|
# use 'less' viewer if output is static
|
|
|
|
project.compose_run_less(compose_cmd)
|
2020-08-17 13:00:05 +00:00
|
|
|
|
|
|
|
return True
|