Rotating log files revisited!

As I told you back in Chapter 7, Working with System Files, this chapter will present you with a technique that will allow you to end the program and rotate log files in a more conventional way with the help of signals and signal handling.

The name of the new version of rotateLog.go will be rotateSignals.go and will be presented in four parts. Moreover, when the utility receives os.Interrupt, it will rotate the current log file, whereas when it receives syscall.SIGTERM, it will terminate its execution. Every other signal that can be handled will create a log entry without any other action.

The first part of the rotateSignals.go is the expected preamble:

package main import ( "fmt" "log" "os" "os/signal" "strconv" ...

Get Go Systems Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.