This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
56 lines (47 loc) · 1.55 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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 log is a context based logging package, designed to interact well
// with both the lsp protocol and the other telemetry packages.
package log
import (
"context"
"time"
"github.com/slrtbtfs/go-tools-vendored/telemetry"
"github.com/slrtbtfs/go-tools-vendored/telemetry/export"
"github.com/slrtbtfs/go-tools-vendored/telemetry/tag"
)
type Event telemetry.Event
// With sends a tag list to the installed loggers.
func With(ctx context.Context, tags ...telemetry.Tag) {
export.Log(ctx, telemetry.Event{
At: time.Now(),
Tags: tags,
})
}
// Print takes a message and a tag list and combines them into a single tag
// list before delivering them to the loggers.
func Print(ctx context.Context, message string, tags ...tag.Tagger) {
export.Log(ctx, telemetry.Event{
At: time.Now(),
Message: message,
Tags: tag.Tags(ctx, tags...),
})
}
// Print takes a message and a tag list and combines them into a single tag
// list before delivering them to the loggers.
func Error(ctx context.Context, message string, err error, tags ...tag.Tagger) {
if err == nil {
err = errorString(message)
message = ""
}
export.Log(ctx, telemetry.Event{
At: time.Now(),
Message: message,
Error: err,
Tags: tag.Tags(ctx, tags...),
})
}
type errorString string
// Error allows errorString to conform to the error interface.
func (err errorString) Error() string { return string(err) }