qrz/vendor/github.com/gobuffalo/logger/logger.go
Paul Lecuq 36c5d6f2ed
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
large change on qrz
- web service with json support
- web page
- cron service to update database infos
2020-05-09 19:09:27 +02:00

68 lines
1.6 KiB
Go

package logger
import (
"os"
"github.com/sirupsen/logrus"
)
// FieldLogger interface
type FieldLogger interface {
Logger
WithField(string, interface{}) FieldLogger
WithFields(map[string]interface{}) FieldLogger
}
// Logger interface is used throughout Buffalo
// apps to log a whole manner of things.
type Logger interface {
Debugf(string, ...interface{})
Infof(string, ...interface{})
Printf(string, ...interface{})
Warnf(string, ...interface{})
Errorf(string, ...interface{})
Fatalf(string, ...interface{})
Debug(...interface{})
Info(...interface{})
Warn(...interface{})
Error(...interface{})
Fatal(...interface{})
Panic(...interface{})
}
func ParseLevel(level string) (Level, error) {
l, err := logrus.ParseLevel(level)
return Level(l), err
}
// NewLogger based on the specified log level, defaults to "debug".
// See `New` for more details.
func NewLogger(level string) FieldLogger {
lvl, err := logrus.ParseLevel(level)
if err != nil {
lvl = logrus.DebugLevel
}
return New(lvl)
}
// New based on the specified log level, defaults to "debug".
// This logger will log to the STDOUT in a human readable,
// but parseable form.
/*
Example: time="2016-12-01T21:02:07-05:00" level=info duration=225.283µs human_size="106 B" method=GET path="/" render=199.79µs request_id=2265736089 size=106 status=200
*/
func New(lvl Level) FieldLogger {
e := os.Getenv("GO_ENV")
if len(e) == 0 {
e = "development"
}
dev := e == "development"
l := logrus.New()
l.SetOutput(os.Stdout)
l.Level = lvl
l.Formatter = &textFormatter{
ForceColors: dev,
}
return Logrus{l}
}