I am using lumberjack and zap logger to log for go based application which deals with multiple nodes, I want to rotate my files based on the status of the node, if a node gets down then log should be rotated and once the node becomes active again it should log it to a new file. I tried the following code :
func sigHup(lumberLogger *lumberjack.Logger) {
// lubberLogger := &lumberjack.Logger{}
// log.SetOutput(lubberLogger)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for {
<-c
lumberLogger.Rotate()
}
}()
}
func getWriteSyncer(logName string) zapcore.WriteSyncer {
var ioWriter = &lumberjack.Logger{
Filename: logName,
MaxSize: 10, // MB
MaxBackups: 3, // number of backups
MaxAge: 28, //days
LocalTime: true,
Compress: false, // disabled by default
}
sigHup(ioWriter)
var sw = WriteSyncer{
ioWriter,
}
return sw
}
Will sighup keeps on checking the status of the nodes?