github.com/mayra-cabrera/buffalo@v0.9.4-0.20170814145312-66d2e7772f11/logger.go (about)

     1  package buffalo
     2  
     3  import (
     4  	"github.com/gobuffalo/envy"
     5  	"github.com/sirupsen/logrus"
     6  )
     7  
     8  // Logger interface is used throughout Buffalo
     9  // apps to log a whole manner of things.
    10  type Logger interface {
    11  	WithField(string, interface{}) Logger
    12  	WithFields(map[string]interface{}) Logger
    13  	Debugf(string, ...interface{})
    14  	Infof(string, ...interface{})
    15  	Printf(string, ...interface{})
    16  	Warnf(string, ...interface{})
    17  	Errorf(string, ...interface{})
    18  	Fatalf(string, ...interface{})
    19  	Debug(...interface{})
    20  	Info(...interface{})
    21  	Warn(...interface{})
    22  	Error(...interface{})
    23  	Fatal(...interface{})
    24  	Panic(...interface{})
    25  }
    26  
    27  var _ Logger = logrusWrapper{}
    28  
    29  type logrusWrapper struct {
    30  	logrus.FieldLogger
    31  }
    32  
    33  func (l logrusWrapper) WithField(s string, i interface{}) Logger {
    34  	return logrusWrapper{l.FieldLogger.WithField(s, i)}
    35  }
    36  
    37  func (l logrusWrapper) WithFields(m map[string]interface{}) Logger {
    38  	return logrusWrapper{l.FieldLogger.WithFields(m)}
    39  }
    40  
    41  // NewLogger based on the specified log level.
    42  // This logger will log to the STDOUT in a human readable,
    43  // but parseable form.
    44  /*
    45  	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
    46  */
    47  func NewLogger(level string) Logger {
    48  	dev := envy.Get("GO_ENV", "development") == "development"
    49  	l := logrus.New()
    50  	l.Level, _ = logrus.ParseLevel(level)
    51  	l.Formatter = &textFormatter{
    52  		ForceColors: dev,
    53  	}
    54  	return logrusWrapper{l}
    55  }