| 1 |
// Copyright 2013 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package log_test |
| 6 |
|
| 7 |
import ( |
| 8 |
"bytes" |
| 9 |
"fmt" |
| 10 |
"log" |
| 11 |
) |
| 12 |
|
| 13 |
func ExampleLogger() { |
| 14 |
var ( |
| 15 |
buf bytes.Buffer |
| 16 |
logger = log.New(&buf, "logger: ", log.Lshortfile) |
| 17 |
) |
| 18 |
|
| 19 |
logger.Print("Hello, log file!") |
| 20 |
|
| 21 |
fmt.Print(&buf) |
| 22 |
// Output: |
| 23 |
// logger: example_test.go:19: Hello, log file! |
| 24 |
} |
| 25 |
|
| 26 |
func ExampleLogger_Output() { |
| 27 |
var ( |
| 28 |
buf bytes.Buffer |
| 29 |
logger = log.New(&buf, "INFO: ", log.Lshortfile) |
| 30 |
|
| 31 |
infof = func(info string) { |
| 32 |
logger.Output(2, info) |
| 33 |
} |
| 34 |
) |
| 35 |
|
| 36 |
infof("Hello world") |
| 37 |
|
| 38 |
fmt.Print(&buf) |
| 39 |
// Output: |
| 40 |
// INFO: example_test.go:36: Hello world |
| 41 |
} |