Skip to content

Instantly share code, notes, and snippets.

@gokusenz
Last active October 16, 2018 16:19
Show Gist options
  • Save gokusenz/f2a2c14f57f2ee7e509d14c5119880d3 to your computer and use it in GitHub Desktop.
Save gokusenz/f2a2c14f57f2ee7e509d14c5119880d3 to your computer and use it in GitHub Desktop.
It's the only was we can get Stackdriver to display logs correctly when running as a Kubernetes app in Google's cloud.
type OutputSplitter struct{}
func (splitter *OutputSplitter) Write(p []byte) (n int, err error) {
if bytes.Contains(p, []byte("error")) {
return os.Stderr.Write(p)
}
return os.Stdout.Write(p)
}
logrus.SetOutput(&OutputSplitter{})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment