Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change log file name dynamically #41

Open
alannaidon opened this issue Mar 27, 2020 · 1 comment
Open

Change log file name dynamically #41

alannaidon opened this issue Mar 27, 2020 · 1 comment

Comments

@alannaidon
Copy link

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!

@rifflock
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants