コード例 #1
0
ファイル: benchmark_test.go プロジェクト: go-playground/log
// NOTE: log is a singleton, which means handlers need to be
// setup only once otherwise each test just adds another log
// handler and results are cumulative... makes benchmarking
// annoying because you have to manipulate the TestMain before
// running the benchmark you want.
func TestMain(m *testing.M) {

	cLog := console.New()
	cLog.SetDisplayColor(false)
	cLog.SetWriter(ioutil.Discard)
	cLog.SetBuffersAndWorkers(3, 3)

	log.RegisterHandler(cLog, log.AllLevels...)

	logrus.SetFormatter(&logrus.TextFormatter{})
	logrus.SetOutput(ioutil.Discard)
	logrus.SetLevel(logrus.InfoLevel)

	os.Exit(m.Run())
}
コード例 #2
0
ファイル: main.go プロジェクト: go-playground/log
func main() {

	cLog := console.New()

	log.RegisterHandler(cLog, log.AllLevels...)

	// Trace
	defer log.Trace("trace").End()

	log.Debug("debug")
	log.Info("info")
	log.Notice("notice")
	log.Warn("warn")
	log.Error("error")
	// log.Panic("panic") // this will panic
	log.Alert("alert")
	// log.Fatal("fatal") // this will call os.Exit(1)

	// logging with fields can be used with any of the above
	log.WithFields(log.F("key", "value")).Info("test info")
}