Skip to content

Commit 164efd3

Browse files
committed
reduce redundant output when capturing late logs
it's unclear if late logs ever captures logs not already echoed, but this at least eliminates the redundant output
1 parent eb75209 commit 164efd3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

repo2docker/app.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import shutil
1717
import tempfile
1818
import time
19-
20-
from .engine import BuildError, ContainerEngineException, ImageLoadError
2119
from urllib.parse import urlparse
20+
2221
import escapism
22+
from iso8601 import parse_date
2323
from pythonjsonlogger import jsonlogger
2424

2525
from traitlets import Any, Dict, Int, List, Unicode, Bool, default
@@ -38,6 +38,7 @@
3838
RBuildPack,
3939
)
4040
from . import contentproviders
41+
from .engine import BuildError, ContainerEngineException, ImageLoadError
4142
from .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:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def get_identifier(json):
5050
"docker",
5151
"entrypoints",
5252
"escapism",
53+
"iso8601",
5354
"jinja2",
5455
"python-json-logger",
5556
"requests",

0 commit comments

Comments
 (0)