-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_exporter.go
More file actions
50 lines (43 loc) · 828 Bytes
/
Copy pathlog_exporter.go
File metadata and controls
50 lines (43 loc) · 828 Bytes
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
package pulse
import (
"context"
"encoding/json"
"io"
"os"
"sync"
)
type LogExporterConfig struct {
Output io.Writer
Pretty bool
}
// LogExporter writes samples as JSON lines.
type LogExporter struct {
mu sync.Mutex
out io.Writer
pretty bool
}
func NewLogExporter(cfg LogExporterConfig) *LogExporter {
out := cfg.Output
if out == nil {
out = os.Stdout
}
return &LogExporter{out: out, pretty: cfg.Pretty}
}
func (e *LogExporter) Name() string { return "log" }
func (e *LogExporter) Export(_ context.Context, samples []Sample) error {
e.mu.Lock()
defer e.mu.Unlock()
enc := json.NewEncoder(e.out)
if e.pretty {
enc.SetIndent("", " ")
}
for _, s := range samples {
if err := enc.Encode(s); err != nil {
return err
}
}
return nil
}
func (e *LogExporter) Close() error {
return nil
}