2020-04-04 21:16:06 -06:00
|
|
|
// 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"
|
|
|
|
|
2020-04-17 07:32:56 -06:00
|
|
|
"golang.org/x/tools/internal/event"
|
|
|
|
"golang.org/x/tools/internal/event/core"
|
|
|
|
"golang.org/x/tools/internal/event/export"
|
2020-04-20 19:50:02 -06:00
|
|
|
"golang.org/x/tools/internal/event/keys"
|
2020-04-20 13:44:34 -06:00
|
|
|
"golang.org/x/tools/internal/event/label"
|
2020-04-04 21:16:06 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleLog() {
|
|
|
|
ctx := context.Background()
|
|
|
|
event.SetExporter(timeFixer(export.LogWriter(os.Stdout, false)))
|
2020-04-20 19:50:02 -06:00
|
|
|
anInt := keys.NewInt("myInt", "an integer")
|
|
|
|
aString := keys.NewString("myString", "a string")
|
2020-04-20 10:14:12 -06:00
|
|
|
event.Log(ctx, "my event", anInt.Of(6))
|
2020-04-04 21:16:06 -06:00
|
|
|
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")
|
2020-04-20 13:44:34 -06:00
|
|
|
return func(ctx context.Context, ev core.Event, lm label.Map) context.Context {
|
2020-04-20 21:00:05 -06:00
|
|
|
copy := core.CloneEvent(ev, at)
|
|
|
|
return output(ctx, copy, lm)
|
2020-04-04 21:16:06 -06:00
|
|
|
}
|
|
|
|
}
|