log: adds a Logger Output method Example

Change-Id: Ia3e351169a4ebe6db5e5f37b668f23dc8c992c78
Reviewed-on: https://go-review.googlesource.com/48877
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
gmarik 2017-07-15 12:11:42 -06:00 committed by Ian Lance Taylor
parent cd619caff4
commit 504deee608
1 changed files with 23 additions and 3 deletions

View File

@ -11,11 +11,31 @@ import (
)
func ExampleLogger() {
var buf bytes.Buffer
logger := log.New(&buf, "logger: ", log.Lshortfile)
var (
buf bytes.Buffer
logger = log.New(&buf, "logger: ", log.Lshortfile)
)
logger.Print("Hello, log file!")
fmt.Print(&buf)
// Output:
// logger: example_test.go:16: Hello, log file!
// logger: example_test.go:19: Hello, log file!
}
func ExampleLogger_Output() {
var (
buf bytes.Buffer
logger = log.New(&buf, "INFO: ", log.Lshortfile)
infof = func(info string) {
logger.Output(2, info)
}
)
infof("Hello world")
fmt.Print(&buf)
// Output:
// INFO: example_test.go:36: Hello world
}