lfshook icon indicating copy to clipboard operation
lfshook copied to clipboard

Change log file name dynamically

Open alannaidon opened this issue 4 years ago • 1 comments

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!

alannaidon avatar Mar 27 '20 14:03 alannaidon

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.

rifflock avatar Jun 22 '20 16:06 rifflock