1616import shutil
1717import tempfile
1818import time
19-
20- from .engine import BuildError , ContainerEngineException , ImageLoadError
2119from urllib .parse import urlparse
20+
2221import escapism
22+ from iso8601 import parse_date
2323from pythonjsonlogger import jsonlogger
2424
2525from traitlets import Any , Dict , Int , List , Unicode , Bool , default
3838 RBuildPack ,
3939)
4040from . import contentproviders
41+ from .engine import BuildError , ContainerEngineException , ImageLoadError
4142from .utils import ByteSpecification , chdir
4243
4344
@@ -629,9 +630,12 @@ def wait_for_container(self, container):
629630 Displaying logs while it's running
630631 """
631632
633+ last_timestamp = None
632634 try :
633- for line in container .logs (stream = True ):
634- self .log .info (line .decode ("utf-8" ), extra = dict (phase = "running" ))
635+ for line in container .logs (stream = True , timestamps = True ):
636+ line = line .decode ("utf-8" )
637+ last_timestamp , line = line .split (" " , maxsplit = 1 )
638+ self .log .info (line , extra = dict (phase = "running" ))
635639
636640 finally :
637641 container .reload ()
@@ -646,9 +650,16 @@ def wait_for_container(self, container):
646650 "Container finished running.\n " .upper (), extra = dict (phase = "running" )
647651 )
648652 # are there more logs? Let's send them back too
649- late_logs = container .logs ().decode ("utf-8" )
653+ if last_timestamp :
654+ # docker only accepts integer timestamps
655+ # this means we will usually replay logs from the last second
656+ # of the container
657+ # we should check if this ever returns anything new,
658+ # since we know it ~always returns something redundant
659+ last_timestamp = int (parse_date (last_timestamp ).timestamp ())
660+ late_logs = container .logs (since = last_timestamp ).decode ("utf-8" )
650661 for line in late_logs .split ("\n " ):
651- self .log .info (line + "\n " , extra = dict (phase = "running" ))
662+ self .log .debug (line + "\n " , extra = dict (phase = "running" ))
652663
653664 container .remove ()
654665 if exit_code :
0 commit comments