Commit 504deee6 authored by gmarik's avatar gmarik Committed by Ian Lance Taylor

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: 's avatarIan Lance Taylor <iant@golang.org>
parent cd619caf
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment