koldfront

Building logrotation into your logging library #programming

๐Ÿ•—๏ธŽ - 2023-04-13

.... don't. Just. Don't.

Instead: reopen any open logfiles if you receive a SIGHUP, and let programs like logrotate take care of the rotation.

This is regardless of whether you're a Java library, a Haskell one, or something else.

And never, ever, just don't, rotate the logfile on startup.

If you are running tail -f on the log file while restarting the service and get no feedback, you've been hit by this bad behaviour. Argh.

(Yes, you can use -F but you shouldn't have to. Just sayin'.)

In case you are using something that logs to stdout and doesn't reopen on SIGHUP, timestampit is your friend - just pipe the output through it, and bob's your uncle.

Add comment

To avoid spam many websites make you fill out a CAPTCHA, or log in via an account at a corporation such as Twitter, Facebook, Google or even Microsoft GitHub.

I have chosen to use a more old school method of spam prevention.

To post a comment here, you need to:

ยน Such as Thunderbird, Pan, slrn, tin or Gnus (part of Emacs).

Or, you can fill in this form:

+=