12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package log
- import (
- "fmt"
- "os"
- "github.com/sirupsen/logrus"
- )
- const (
- LogLevel = "LOG"
- )
- var (
- logger = logrus.New()
- )
- func init() {
- envLevel, _ := os.LookupEnv(LogLevel)
- if envLevel == "" {
- envLevel = "info"
- }
- level := logLevel(envLevel)
- logger.SetLevel(level)
- formatter := &logrus.TextFormatter{
- FullTimestamp: false,
- DisableLevelTruncation: true,
- }
- logger.SetFormatter(formatter)
- }
- func logLevel(lvl string) logrus.Level {
- switch lvl {
- case "trace":
- return logrus.TraceLevel
- case "debug":
- return logrus.DebugLevel
- case "info":
- return logrus.InfoLevel
- case "warn":
- return logrus.WarnLevel
- case "error":
- return logrus.ErrorLevel
- case "fatal":
- return logrus.FatalLevel
- default:
- panic(fmt.Sprintf("the specified %s log level is not supported. Use [trace|debug|info|warn|error|fatal]", lvl))
- }
- }
- func Info(values ...interface{}) {
- logger.Info(values...)
- }
- func Infof(fmt string, values ...interface{}) {
- logger.Infof(fmt, values...)
- }
- func Infoln(values ...interface{}) {
- logger.Infoln(values...)
- }
- func Debugf(fmt string, values ...interface{}) {
- logger.Debugf(fmt, values...)
- }
- func Debug(values ...interface{}) {
- logger.Debug(values...)
- }
- func Tracef(fmt string, values ...interface{}) {
- logger.Tracef(fmt, values...)
- }
- func Trace(values ...interface{}) {
- logger.Trace(values...)
- }
- func Warnf(fmt string, values ...interface{}) {
- logger.Warnf(fmt, values...)
- }
- func Fatalf(fmt string, values ...interface{}) {
- logger.Fatalf(fmt, values...)
- }
- func Errorf(fmt string, values ...interface{}) {
- logger.Errorf(fmt, values...)
- }
- func Error(values ...interface{}) {
- logger.Error(values...)
- }
- func Fatal(values ...interface{}) {
- logger.Fatal(values...)
- }
- func IsTrace() bool {
- return logger.IsLevelEnabled(logrus.TraceLevel)
- }
|