Beyond Static Logging Part 2: Changing Go Log Levels at Runtime with Unix Signals
This is part 2 of my Go logging series. If you haven’t read part 1 , I recommend starting there. In that post, we looked at changing log levels dynamically based on error volume. In this post, we’ll look at another approach: using OS signals to change log levels at runtime without restarting the application. The Foundation OS Signals Before we begin, let’s do a quick crash course on OS signals. Signals are a low-level operating system feature, and POSIX standardizes many of the common Unix signal behaviors. They notify a process that an event has happened. That event might be a user pressing Ctrl+C, a terminal closing, or the OS asking the process to terminate. Both Linux and macOS have signal handling although they may not implement the exact same set of signals. You've probably interacted with signals without realizing it. Whenever you send CTRL+c or when you press CTRL+z, this sends a SIGINT and SIGTSTP respectively. ...