#Help Understanding Slog file rotation

6 messages · Page 1 of 1 (latest)

solemn void
#

Hey, y'all. I'm pretty early into my learning of go and I was playing around with using slog. I was hoping to see if anyone could point me toward a resource that might help me understand if there is a built-in method for rotating the file I'm writing on periodically, or if there is a more standard way of rotating a log file.

strong crater
#

Hi 👋 ! slog doesn't file rotation.
They didn't add that because it's not part of actual logging. There are very common tools on various systems that already offers this and there are 3rd party Go modules that have log file rotation.

https://github.com/natefinch/lumberjack
This one is quite popular among Go developers.

GitHub

lumberjack is a log rolling package for Go. Contribute to natefinch/lumberjack development by creating an account on GitHub.

solemn void
strong crater
#

It's common for tools outside of applications to handle log rotation.
Log rotation is solved by a program called logrotate on BSD and Linux systems.
If you run in Kubernetes, the rotation is handled by whatever solution you have for capture stdout and stderr.

solemn void
strong crater
#

You're welcome.
Don't hesitate to ask questions. 🙂