我正在使用lumberjack和zap logger记录处理多个节点的基于go的应用程序,我想根据节点的状态旋转文件,如果一个节点出现故障,则应该旋转日志,并且一旦该节点再次变为活动状态,应将其记录到新文件中。我尝试了以下代码:
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
}
sighup会继续检查节点的状态吗?