Exemple #1
0
package main

import (
	"github.com/square/p2/Godeps/_workspace/src/github.com/Sirupsen/logrus"
)

var log = logrus.New()

func init() {
	log.Formatter = new(logrus.JSONFormatter)
	log.Formatter = new(logrus.TextFormatter) // default
	log.Level = logrus.DebugLevel
}

func main() {
	defer func() {
		err := recover()
		if err != nil {
			log.WithFields(logrus.Fields{
				"omg":    true,
				"err":    err,
				"number": 100,
			}).Fatal("The ice breaks!")
		}
	}()

	log.WithFields(logrus.Fields{
		"animal": "walrus",
		"number": 8,
	}).Debug("Started observing beach")
Exemple #2
0
func NewLogger(baseFields logrus.Fields) Logger {
	logger := Logger{logrus.New(), baseFields}
	logger.Logger.Formatter = new(logrus.JSONFormatter)
	return logger
}