2
2
3
3
import functools
4
4
import logging
5
- import os
6
5
import sys
7
6
import threading
8
7
from abc import ABC , abstractmethod
14
13
from docker .errors import NotFound
15
14
from docker .types import IPAMConfig , IPAMPool
16
15
17
- from launcher .utils import get_hostfs_file , ArgumentParser , yes_or_no
16
+ from launcher .utils import ArgumentParser , yes_or_no
18
17
from .DockerTemplate import DockerTemplate
19
18
from .arby import Arby
20
19
from .base import Node , ContainerNotFound , NoWaiting
@@ -52,19 +51,25 @@ def execute(self, *args) -> None:
52
51
class LogsCommand (Command ):
53
52
def create_parser (self ) -> ArgumentParser :
54
53
parser = ArgumentParser (prog = "logs" , description = "fetch the logs of a container" )
55
- parser .add_argument ("--tail" , "-t" , metavar = 'N' , type = int ,
56
- help = "number of lines to show from the end of the logs" , default = 100 )
57
- parser .add_argument ("--since" , "-s" )
54
+ parser .add_argument ("--tail" , metavar = 'N' ,
55
+ help = "number of lines to show from the end of the logs (default \" 100\" )" ,
56
+ default = "100" )
57
+ parser .add_argument ("--since" ,
58
+ help = "show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)" )
59
+ parser .add_argument ("--until" ,
60
+ help = "show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)" )
61
+ parser .add_argument ("--follow" , "-f" , action = "store_true" ,
62
+ help = "follow log output" )
63
+ parser .add_argument ("--timestamps" , "-t" , action = "store_true" ,
64
+ help = "show timestamps" )
58
65
parser .add_argument ("service" )
59
66
return parser
60
67
61
68
def execute (self , * args ) -> None :
62
69
args = self .parser .parse_args (args )
63
70
name = args .service
64
- tail = args .tail
65
- since = args .since
66
71
service = self .get_service (name )
67
- for line in service .logs (tail = tail , since = since ):
72
+ for line in service .logs (tail = args . tail , since = args . since , until = args . until , follow = args . follow , timestamps = args . timestamps ):
68
73
print (line )
69
74
70
75
@@ -354,12 +359,12 @@ def status(self):
354
359
print (f"{ border_style } ┌─%s─┬─%s─┐{ RESET } " % ("─" * col1_width , "─" * col2_width ))
355
360
print (
356
361
f"{ border_style } │{ RESET } { title_style } %s{ RESET } { border_style } │{ RESET } { title_style } %s{ RESET } { border_style } │{ RESET } " % (
357
- col1_fmt % col1_title , col2_fmt % col2_title ))
362
+ col1_fmt % col1_title , col2_fmt % col2_title ))
358
363
for name in names :
359
364
print (f"{ border_style } ├─%s─┼─%s─┤{ RESET } " % ("─" * col1_width , "─" * col2_width ))
360
365
print (
361
366
f"{ border_style } │{ RESET } { service_style } %s{ RESET } { border_style } │{ RESET } { border_style } %s{ RESET } { border_style } │{ RESET } " % (
362
- col1_fmt % name , col2_fmt % "" ))
367
+ col1_fmt % name , col2_fmt % "" ))
363
368
print (f"{ border_style } └─%s─┴─%s─┘{ RESET } " % ("─" * col1_width , "─" * col2_width ))
364
369
365
370
lock = threading .Lock ()
@@ -372,10 +377,10 @@ def update_line(name, text, fetching=False):
372
377
x = col1_width + 2
373
378
if fetching :
374
379
print (f"\033 [%dA\033 [%dC{ border_style } %s{ RESET } \033 [%dD\033 [%dB" % (
375
- y , x + 3 , col2_fmt % text [:col2_width ], x + col2_width + 3 , y ), end = "" )
380
+ y , x + 3 , col2_fmt % text [:col2_width ], x + col2_width + 3 , y ), end = "" )
376
381
else :
377
382
print ("\033 [%dA\033 [%dC%s\033 [%dD\033 [%dB" % (
378
- y , x + 3 , col2_fmt % text [:col2_width ], x + col2_width + 3 , y ), end = "" )
383
+ y , x + 3 , col2_fmt % text [:col2_width ], x + col2_width + 3 , y ), end = "" )
379
384
sys .stdout .flush ()
380
385
381
386
result = {name : None for name in names }
0 commit comments