Skip to content

Commit

Permalink
feat: send error logs to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Oct 5, 2021
1 parent fa64809 commit f318ebf
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions shared/util/log.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package util

import (
"os"

"github.com/bombsimon/logrusr"
"github.com/go-logr/logr"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/writer"
"io"

"os"
)

func NewLogger() logr.Logger {
l := logrus.New()
l.SetOutput(os.Stdout)
l := log.New()
l.SetOutput(io.Discard)
l.AddHook(&writer.Hook{
Writer: os.Stderr,
LogLevels: []log.Level{
log.PanicLevel,
log.FatalLevel,
log.ErrorLevel,
log.WarnLevel,
},
})
l.AddHook(&writer.Hook{
Writer: os.Stdout,
LogLevels: []log.Level{
log.InfoLevel,
log.DebugLevel,
},
})
return logrusr.NewLogger(l)
}

0 comments on commit f318ebf

Please sign in to comment.