lfshook
lfshook copied to clipboard
Change log file name dynamically
Hello! I'm preparing the log files for a specific level when the application starts like this:
pathMap := MakePath(
fileLevel,
absolutePath,
logPath,
)
func MakePath(minLevel logrus.Level, fpath, logPath string) lfshook.PathMap {
pm := lfshook.PathMap{}
for _, lvl := range logrus.AllLevels {
if lvl <= minLevel {
pm[lvl] = fpath
}
pm[logrus.WarnLevel] = logPath + "/logs/teste.log"
}
return pm
}
Is it possible to change configuration for the teste.log
name dynamically?
Or the only way is to change the file after it's creation? (The file will only be created when the first log fires).
Thanks!
Hi! Sorry for the slow reply on this I haven't been getting notifications.
The way it's currently built, you can only set the log file names on construction.
Once you pass your PathMap
to the NewHook
method you're locked in to using those files, but up until that point you can make whatever changes you want.