New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/logging compression #3261

wants to merge 1 commit into
base: master


None yet
3 participants

teeg82 commented Jan 7, 2019

- What I did

  • Modified pkg/logwrite to include a boolean option to compress log files as they rotate
    • The -compress option defaults to false, to preserve the existing behaviour.
  • Updated logging documentation to mention compression option
  • This feature was born from this discussion (#3072 (comment))

- How I did it
This is a modification of the original logging infrastructure created by @djs55 in #3095

  • Added new function to handle compression using compress/gzip package
  • Compression occurs immediately prior to rotation if enabled.
    • For clarity, compressed files will be appended with .gz
      • File lookup during rotation will attempt to locate files expecting this extension when compression is enabled.
      • Note: With this implementation, this means that if compression is enabled after a period of time, the existing uncompressed logs will be ignored forever. The same occurs for the compressed logs if disabling compression after a period of time. Basically, toggling back and forth may create some left over files. This doesn't seem like it should be a big deal, but I'm happy to put some more work into it to make it more robust if needed.

- How to verify it

  1. Create a logging.yml file with the following:

       image: linuxkit/kernel:4.14.91
       cmdline: "console=tty0 console=ttyS0 console=ttyAMA0"
       - linuxkit/init:c563953a2277eb73a89d89f70e4b6dcdcfebc2d1
       - linuxkit/runc:83d0edb4552b1a5df1f0976f05f442829eac38fe
       - linuxkit/containerd:326b096cd5fbab0f864e52721d036cade67599d6
       - linuxkit/ca-certificates:v0.6
       - linuxkit/memlogd:v0.6
       - name: sysctl
         image: linuxkit/sysctl:v0.6
       - name: dhcpcd
         image: linuxkit/dhcpcd:v0.6
         command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
     # Inside the getty type `/proc/1/root/usr/bin/logread -F` to follow the log
       - name: getty
         image: linuxkit/getty:2eb742cd7a68e14cf50577c02f30147bc406e478
          - INSECURE=true
     # A service which generates log messages for testing
       - name: write-to-the-logs
         image: alpine:3.8
         command: ["/bin/sh", "-c", "while /bin/true; do echo hello $(date); sleep 1; done" ]
       - name: logwrite
         image: linuxkit/logwrite
         command: ["/usr/bin/logwrite", "-max-log-size", "20480", "-compress", "true"]
       - name: kmsg
         image: linuxkit/kmsg:v0.6
         - linuxkit
         - library
  2. linuxkit build -disable-content-trust logging.yml

  3. linuxkit run logging

  4. In getty, run watch ls -l /var/log

  5. You should expect to see a file called write-to-the-logs.log filling up to about 20kb, before rotating. After several minutes, you should expect to see at least 1 rotated compressed file a fraction of the size of the original, marked with .gz.

Example output:

Every 2s: ls -l                                             2019-01-07 18:57:47

total 68
-rw-r--r--    1 root     root           405 Jan  7 18:29 getty.out.log
-rw-r--r--    1 root     root          3352 Jan  7 18:29 kmsg.log
-rw-r--r--    1 root     root          4492 Jan  7 18:29 kmsg.log.0.gz
-rw-r--r--    1 root     root          4820 Jan  7 18:29 kmsg.log.1.gz
-rw-r--r--    1 root     root            45 Jan  7 18:29 memlogd.log
-rw-r--r--    1 root     root          1047 Jan  7 18:29 onboot.001-dhcpcd.log
-rw-r--r--    1 root     root         11935 Jan  7 18:57 write-to-the-logs.out.log
-rw-r--r--    1 root     root          1471 Jan  7 18:55 write-to-the-logs.out.log.0.gz
-rw-r--r--    1 root     root          1521 Jan  7 18:50 write-to-the-logs.out.log.1.gz
-rw-r--r--    1 root     root          1473 Jan  7 18:45 write-to-the-logs.out.log.2.gz
-rw-r--r--    1 root     root          1536 Jan  7 18:41 write-to-the-logs.out.log.3.gz
-rw-r--r--    1 root     root          1472 Jan  7 18:36 write-to-the-logs.out.log.4.gz
-rw-r--r--    1 root     root          1519 Jan  7 18:32 write-to-the-logs.out.log.5.gz

- Description for the changelog

Adding option to allow log files to compress after rotation

- A picture of a cute animal (not mandatory but encouraged)


This comment has been minimized.


GordonTheTurtle commented Jan 7, 2019

Please sign your commits following these rules:
The easiest way to do this is to amend the last commit:

$ git clone -b "feature/logging-compression" somewhere
$ cd somewhere
$ git rebase -i HEAD~842354463312
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@teeg82 teeg82 force-pushed the navcanada:feature/logging-compression branch from 55c77e0 to c52eadf Jan 7, 2019


This comment has been minimized.

teeg82 commented Jan 11, 2019

@GordonTheTurtle I believe I've fixed commit signature


This comment has been minimized.


justincormack commented Jan 11, 2019

Hey, doesn't look like your commits are signed. It might be easier if you squash them into one first.

Add ability to optionally compress logfiles just prior to rotation in…
… logwrite package.

Add note about new compression option in logging documentation.

Signed-off-by: Paul Richter <>

@teeg82 teeg82 force-pushed the navcanada:feature/logging-compression branch from c52eadf to 817f717 Jan 11, 2019

@GordonTheTurtle GordonTheTurtle removed the dco/no label Jan 11, 2019


This comment has been minimized.

teeg82 commented Jan 11, 2019

@justincormack 2nd time's the charm, I think I got it this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment