I use logrus and lumberjack for log file on macOS.
logger := &lumberjack.Logger{
// Log path
Filename: filepath.Join(logFolder, "xxx.log"),
// Log size MB
MaxSize: 10,
// Backup count
MaxBackups: 3,
// expire days
// MaxAge: 28,
// gzip compress
Compress: false,
}
logrus.SetOutput(logger)
When I start my application, It will create log file as expected.
However, when my app is running, I manually delete log file, as my app is continuing to run, I expect it will re-create log file, however, the log file is not created.
But if I restart my app, the log file will be created again.
So what should I do to make my app (keep running) to re-create and write log file when log file is deleted.
Thanks in advance.
Here is another way to monitor the log file using
fsnotifylib.fsnotifymonitors the directory where xxx.log is located, tell lumberjack toRotate()when xxx.log deleted.