level: Support multi-line log writes #7
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.
LevelFilter
previously assumed that it would always receive writes one line at a time. Although that is the behavior of the"log"
package itself, log output is sometimes delivered indirectly through other channels. For example, Terraform (and some other HashiCorp software) usesmitchellh/panicwrap
to recognize crashes, which means that log lines are received indirectly through pipe from thepanicwrap
child process, which seems to introduce some additional buffering.This appears to be the root cause of hashicorp/terraform#6468. Since removing
panicwrap
from Terraform would hurt its user experience, here we instead makeLevelFilter
a little more forgiving to accept multiple messages in a single write as long as messages are never split acrossmultiple writes.
This does not change the results for callers that are using the
"log"
package directly, and it makes the behavior a little more resilient to other intermediaries processing log output, as long as those intermediaries don't cause any atomic writes to be split into multiple parts before they reach the log writer. That is true forpanicwrap
's pipes, allowing Terraform's log output to then be filtered correctly in spite ofpanicwrap
.