mirror of
https://github.com/golang/go
synced 2024-11-06 07:26:10 -07:00
d780ff7bdd
This is now the only package that is exposed to normal use, and should be the only thing to appear in libraries. Change-Id: I90ee47c6519f30db16ff5d5d2910be86e91e5df2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222557 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Copyright 2019 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 event
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// Log sends a log event with the supplied tag list to the exporter.
|
|
func Log(ctx context.Context, tags ...Tag) {
|
|
ProcessEvent(ctx, Event{
|
|
Type: LogType,
|
|
At: time.Now(),
|
|
Tags: tags,
|
|
})
|
|
}
|
|
|
|
// Print takes a message and a tag list and combines them into a single event
|
|
// before delivering them to the exporter.
|
|
func Print(ctx context.Context, message string, tags ...Tag) {
|
|
ProcessEvent(ctx, Event{
|
|
Type: LogType,
|
|
At: time.Now(),
|
|
Message: message,
|
|
Tags: tags,
|
|
})
|
|
}
|
|
|
|
// Error takes a message and a tag list and combines them into a single event
|
|
// before delivering them to the exporter. It captures the error in the
|
|
// delivered event.
|
|
func Error(ctx context.Context, message string, err error, tags ...Tag) {
|
|
if err == nil {
|
|
err = errors.New(message)
|
|
message = ""
|
|
}
|
|
ProcessEvent(ctx, Event{
|
|
Type: LogType,
|
|
At: time.Now(),
|
|
Message: message,
|
|
Error: err,
|
|
Tags: tags,
|
|
})
|
|
}
|