mirror of
https://github.com/golang/go
synced 2024-11-18 14:04:45 -07:00
a466788a31
This was the last piece of Event that was public, and it was only public to allow mutation in tests. Adding CloneEvent allows tests to create an updated copy rather than update the event in place. Change-Id: I2215d1eb0317063948ef0fac955fa768a209564d Reviewed-on: https://go-review.googlesource.com/c/tools/+/229241 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package export_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"time"
|
|
|
|
"golang.org/x/tools/internal/event"
|
|
"golang.org/x/tools/internal/event/core"
|
|
"golang.org/x/tools/internal/event/export"
|
|
"golang.org/x/tools/internal/event/keys"
|
|
"golang.org/x/tools/internal/event/label"
|
|
)
|
|
|
|
func ExampleLog() {
|
|
ctx := context.Background()
|
|
event.SetExporter(timeFixer(export.LogWriter(os.Stdout, false)))
|
|
anInt := keys.NewInt("myInt", "an integer")
|
|
aString := keys.NewString("myString", "a string")
|
|
event.Log(ctx, "my event", anInt.Of(6))
|
|
event.Error(ctx, "error event", errors.New("an error"), aString.Of("some string value"))
|
|
// Output:
|
|
// 2020/03/05 14:27:48 my event
|
|
// myInt=6
|
|
// 2020/03/05 14:27:48 error event: an error
|
|
// myString="some string value"
|
|
}
|
|
|
|
func timeFixer(output event.Exporter) event.Exporter {
|
|
at, _ := time.Parse(time.RFC3339Nano, "2020-03-05T14:27:48Z")
|
|
return func(ctx context.Context, ev core.Event, lm label.Map) context.Context {
|
|
copy := core.CloneEvent(ev, at)
|
|
return output(ctx, copy, lm)
|
|
}
|
|
}
|