Skip to content

Instantly share code, notes, and snippets.

@AndreKR
Last active October 7, 2019 17:31
Show Gist options
  • Save AndreKR/64af06c9da83d31b2e759beea9387efc to your computer and use it in GitHub Desktop.
Save AndreKR/64af06c9da83d31b2e759beea9387efc to your computer and use it in GitHub Desktop.
Initializing logrus
// The state of Go logging libraries is disheartening...
import (
"github.com/mattn/go-colorable" // not ansicolor because github.com/mgutz/ansi recommends colorable
log "github.com/sirupsen/logrus"
"github.com/x-cray/logrus-prefixed-formatter"
"golang.org/x/crypto/ssh/terminal"
"os"
)
func init() {
log.SetFormatter(&prefixed.TextFormatter{
ForceColors: true,
ForceFormatting: terminal.IsTerminal(int(os.Stderr.Fd())),
})
log.SetOutput(ansicolor.NewAnsiColorWriter(os.Stderr))
log.SetLevel(log.DebugLevel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment