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
Add method for setting default file or writer #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely makes it cleaner than having to create a map of identical paths/writers.
Ideally we'd be able to set a default path AND a path map (or writer and writer map) in the constructor, but I'd hate to change the constructor signature again.
lfshook.go
Outdated
switch levelMap.(type) { | ||
case nil: | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go this path it might be good to instead support a case for string
(default path) and a case for io.Writer
(default writer).
I'm not a big fan of allowing the user to successful create a hook that has no valid output paths configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done on 83da246.
I tried to resolve the merge conflicts to the Readme, but it wouldn't let me (probably because it's your branch). If you can fix those then I can merge it. |
@rifflock done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Should be a non-breaking change.
The main focus of this PR is to add new method for setting default output file if there are no output defined for some or all log level. This method is especially useful if you want to put all log level to single file.
Code above will make a
general.log
file which contains all logs :While adding this method, I fixed some bugs :
lfshook
will fail to create new log file if target directory doesn't exist.TextFormatter
, which make log files looks weird.