]> Cypherpunks repositories - gostls13.git/commitdiff
log: adds a Logger Output method Example
authorgmarik <gmarik@gmail.com>
Sat, 15 Jul 2017 18:11:42 +0000 (12:11 -0600)
committerIan Lance Taylor <iant@golang.org>
Sun, 16 Jul 2017 03:57:11 +0000 (03:57 +0000)
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>
src/log/example_test.go

index 74385a3a0ae802c2dc2e3bc2c800c98d4804c6ca..769d076e9d59870bc93cacee20dd5e57d08ebd70 100644 (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
 }