Skip to content

Instantly share code, notes, and snippets.

@socheatsok78
Last active October 13, 2023 11:43
Show Gist options
  • Save socheatsok78/fbb90cf89984cf5e1110482cbe3a09a9 to your computer and use it in GitHub Desktop.
Save socheatsok78/fbb90cf89984cf5e1110482cbe3a09a9 to your computer and use it in GitHub Desktop.
s6-overlay logging configuration

Logging

The log will be written to both /var/log/some-service as well as standard output.

The key is that s6-log reads in a whole "logging script" on the command line, and you can have multiple actions - here's the link to the manual.

S6_LOGGING_SCRIPT="T 1 n20 s1000000 T"
  • s6-log -bp - call s6-log in blocking, protected mode (same as logutil-service does)

  • T 1 -- this is my first action directive

    • take all lines of input (because I don't have any line selection directives)
    • prepend with an ISO 8601 timestamp (done with T)
    • forward to stdout (done with the 1)
  • n20 s1000000 T /var/log/some-service -- this is second first action directive, and it's the default mode for logutil-service

    • take all lines of input (again, no selection directives)
    • keep up to 20 files (n20)
    • each file is max 1000000 bytes (s1000000)
    • prepend with an ISO 8601 timestamp (T)
    • save to logdir /var/log/some-service

Ref: just-containers/s6-overlay#252

myapp-log-prepare/up

Simple

if { mkdir -p /var/log/myapp }
if { chown nobody:nogroup /var/log/myapp }
chmod 02755 /var/log/myapp

Custom

envfile /etc/myapp-env
importas myapp_version MYAPP_VERSION

foreground {
    if { mkdir -p /var/log/myapp/$myapp_version }
    if { chown nobody:nogroup /var/log/myapp/$myapp_version }
    chmod 02755 /var/log/myapp/$myapp_version
}

# This line will be executed regardless of the exit status in the if above
echo "[INFO] myapp-log-prepare: The log files are stored in /var/log/myapp/$myapp_version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment