Skip to content

Instantly share code, notes, and snippets.

@AndreKR
Last active Oct 7, 2019
Embed
What would you like to do?
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