1 // Copyright 2016 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.
15 var bufPool
= sync
.Pool
{
16 New
: func() interface{} {
17 // The Pool's New function should generally only return pointer
18 // types, since a pointer can be put into the return interface
19 // value without an allocation:
20 return new(bytes
.Buffer
)
24 // timeNow is a fake version of time.Now for tests.
25 func timeNow() time
.Time
{
26 return time
.Unix(1136214245, 0)
29 func Log(w io
.Writer
, key
, val
string) {
30 b
:= bufPool
.Get().(*bytes
.Buffer
)
32 // Replace this with time.Now() in a real logger.
33 b
.WriteString(timeNow().UTC().Format(time
.RFC3339
))
43 Log(os
.Stdout
, "path", "/search?q=flowers")
44 // Output: 2006-01-02T15:04:05Z path=/search?q=flowers