Skip to content

Suggestion: add option to keep docker logs #89

@vga101

Description

@vga101

I understand that running applications and services within docker containers generally should leave (almost) no traces and possibly fill up the the disk space. However, for development and debugging purposes, it can be very helpful if some information is retained that permits tracking down bugs or weird behaviours. For many applications and scripts, debug information may be printed to stdout/stderr and end up in the docker logs, but these also get lost when containers is removed.

For your consideration, I'm suggesting to add a way to keep this information if required. Currently I have a patched version of hilbert-station that does that for docker-compose. This approach certainly is not worked out, but may serve as a basis for your consideration.

--- /opt/hilbert-cli/bin/hilbert-station.orig   2018-06-05 17:14:27.502598971 +0200
+++ /opt/hilbert-cli/bin/hilbert-station        2018-06-05 18:28:43.409097608 +0200
@@ -1586,6 +1586,13 @@

 #    cmd_docker_compose kill -s SIGTERM "$d"  #    cmd_docker_compose kill -s SIGKILL "$d"
     cmd_docker_compose stop -t "${hibert_station_process_kill_timeout}" "$d"
+
+    local date=$( date -Is )
+    local logdir="$HOME/.config/hilbert-station/logs"
+    mkdir -p "$logdir"
+    cmd_docker_compose logs --timestamps --no-color "$d" >>"$logdir/$d.$date.log" 2>&1
+
     cmd_docker_compose rm -vf "$d"
 #    _ret=$?
     cmd_docker_compose rm -vf "$d"  # NOTE: to remove "dead" left-over containers!

I have the logs written to the local hilbert-station config directory, which also keeps old configurations. Log rotation might be added to avoid filling up disk space, but that may be a thing of over-engineering it already.

Activating this feature might be done by setting a variable in Hilbert.yml, either for a specific station or for a "station_defaults" template that will get inherited by respective stations. The activation variable could well be the subdirectory within ~/.config/hilbert-station/, e.g. logs, and have it disabled by default (if string empty or not set).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions