예제 #1
0
파일: api_test.go 프로젝트: One-com/gonelog
func ExampleContext() {
	log.SetPrefix("PFX:")
	log.SetOutput(os.Stdout)
	log.SetFlags(log.LminFlags | log.Lshortfile)

	log.ERROR("hi", log.KV{"key": "val"})
	log.WARN("lazy", "hip", log.Lazy(func() interface{} { return "slow" }))

	cancel_context, cancel_func := context.WithCancel(context.Background())
	logger := log.With(log.KV{"tra": "la"})
	logger.DoCodeInfo(true)
	logging_context := context.WithLogging(cancel_context, logger)

	ok := make(chan struct{})

	go f(logging_context, ok)

	h(logger)
	g(logging_context)

	time.Sleep(time.Duration(1) * time.Second)

	cancel_func() // cancel the go-routine

	// wait for its exit
	select {
	case <-ok:
	}
	// Output:
	//<3>PFX:api_test.go:50: hi key=val
	//<4>PFX:api_test.go:51: lazy hip=slow
	//<5>PFX:api_test.go:26: H1 tra=la
	//<5>PFX:api_test.go:27: H2
	//<5>PFX:api_test.go:31: G tra=la a=b
	//<5>PFX:api_test.go:38: cancelled tra=la
}
예제 #2
0
파일: api_test.go 프로젝트: One-com/gonelog
func ExampleMinimal() {
	log.Minimal() // change default Logger to not be stdlib compatible but minimal
	log.ERROR("fejl")
	// Output:
	// <3>fejl
}