src.dualinventive.com/go/lib/dilog/logger.go

36 lines
818 B
Go

package dilog
import (
"io/ioutil"
"github.com/sirupsen/logrus"
)
// Fields are log fields to log, it is an map[string]interface{}
type Fields = logrus.Fields
// Discard is the always present nil-logger
var Discard = NewNilLogger()
// Logger is the generic logger type which has all required logging attributes
type Logger interface {
WithField(key string, value interface{}) Logger
WithFields(fields Fields) Logger
WithError(err error) Logger
Debug(args ...interface{})
Info(args ...interface{})
Warning(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})
}
// NewNilLogger returns a /dev/null logger which logs to nowhere
func NewNilLogger() Logger {
logger := logrus.New()
logger.Out = ioutil.Discard
return &Logrus{logrus.NewEntry(logger)}
}