add option to split streams on severity #671
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #403
#403 was closed with the following rationale:
Since that that time, I've humbly proposed that the use case may not be so narrow. (See comment.)
Since we need this functionality to continue using logrus, I decided to see what I could do with a hook, as had been suggested. I found, quickly, that using a hook wasn't the best idea from a performance standpoint. While I'd be relying on the hook to actually output formatted messaged to
os.Stdout
oros.Stderr
, I'd have to set the logger'sOut
field to something likeioutil.Discard
to avoid getting duplicate messages-- and that's totally fine, except for the fact that the overhead of formatting the message is then incurred twice over, only to discard it in one of those two cases. This didn't seem optimal.Given the upvotes on my proposal that this may not be a narrow use case, I decided to look into how easy it might be to add support for this behavior directly into logrus. It wasn't hard as it turns out, and this PR is the result of that effort.
Please note that, quite importantly, this change preserves original behavior and merely enables the option to split log messages across two different
io.Writer
s, depending on log message severity.