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

Log accordingly to a field, is there possible ? #36

Open
renathoaz opened this issue Mar 14, 2018 · 1 comment
Open

Log accordingly to a field, is there possible ? #36

renathoaz opened this issue Mar 14, 2018 · 1 comment

Comments

@renathoaz
Copy link

I would like to log accodingly to field in the log, like this:
log.WithFields(log.Fields{"Field": "logname"}).Info("My log message!")

So all logs that contains that field would go to logname.log, if I have:
log.WithFields(log.Fields{"Field": "logname2"}).Info("My log message!")
It would go to logname2.log

How can I achieve that ?

@rifflock
Copy link
Owner

Hm... An interesting usecase. Not one I'd considered going into this.

Currently, It's not something that can be done. I set it up to be an exact mapping between entry.Level and a file, then later streams were added. If you want to write a PR you could probably do something similar to the introduction of streams.

If you wanted to add support for file routing by Fields you would need the following:

  • You'd have to add code to the fileWrite method that would allow using something other than entry.Level as the file selector.
  • You'd have to add a Field-Filename map that would be set in the contructor. Similar to the PathMap, and if you just create a different type like FieldPathMap then it could be supported without too much difficulty.

I don't see it as a super complex change, but you'd have to be really careful to not introduce regressions.

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