Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / mvdan.cc / gofumpt@v0.0.0-20200802201014-ab5a8192947d / gofumports / internal / telemetry / event / log.go
1 // Copyright 2019 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 event
6
7 import (
8         "context"
9         "errors"
10         "fmt"
11 )
12
13 // Log sends a log event with the supplied tag list to the exporter.
14 func Log(ctx context.Context, tags ...Tag) {
15         dispatch(ctx, makeEvent(LogType, sTags{}, tags))
16 }
17
18 // Log1 sends a label event to the exporter with the supplied tags.
19 func Log1(ctx context.Context, t1 Tag) context.Context {
20         return dispatch(ctx, makeEvent(LogType, sTags{t1}, nil))
21 }
22
23 // Log2 sends a label event to the exporter with the supplied tags.
24 func Log2(ctx context.Context, t1, t2 Tag) context.Context {
25         return dispatch(ctx, makeEvent(LogType, sTags{t1, t2}, nil))
26 }
27
28 // Log3 sends a label event to the exporter with the supplied tags.
29 func Log3(ctx context.Context, t1, t2, t3 Tag) context.Context {
30         return dispatch(ctx, makeEvent(LogType, sTags{t1, t2, t3}, nil))
31 }
32
33 // Print takes a message and a tag list and combines them into a single event
34 // before delivering them to the exporter.
35 func Print(ctx context.Context, message string, tags ...Tag) {
36         dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message)}, tags))
37 }
38
39 // Print1 takes a message and one tag delivers a log event to the exporter.
40 // It is a customized version of Print that is faster and does no allocation.
41 func Print1(ctx context.Context, message string, t1 Tag) {
42         dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1}, nil))
43 }
44
45 // Print2 takes a message and two tags and delivers a log event to the exporter.
46 // It is a customized version of Print that is faster and does no allocation.
47 func Print2(ctx context.Context, message string, t1, t2 Tag) {
48         dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1, t2}, nil))
49 }
50
51 // Error takes a message and a tag list and combines them into a single event
52 // before delivering them to the exporter. It captures the error in the
53 // delivered event.
54 func Error(ctx context.Context, message string, err error, tags ...Tag) {
55         if err == nil {
56                 err = errors.New(message)
57                 message = ""
58         }
59         dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), Err.Of(err)}, tags))
60 }
61
62 // Debugf sends a log event with the supplied message to the exporter.
63 // This is intended only for temporary debugging lines, and usage should not
64 // normally be checked in, preffering structured log events for things
65 // that have to be used in production.
66 func Debugf(ctx context.Context, message string, args ...interface{}) {
67         dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(fmt.Sprintf(message, args...))}, nil))
68 }