-
Notifications
You must be signed in to change notification settings - Fork 388
/
formattedwriter.go
41 lines (37 loc) · 1.04 KB
/
formattedwriter.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
package logbus
import (
"github.com/earthly/cloud-api/logstream"
)
// FormattedWriter is a writer that produces DeltaFormattedLog messages.
type FormattedWriter struct {
bus *Bus
targetID string
commandID string
}
// NewFormattedWriter creates a new FormattedWriter.
func NewFormattedWriter(bus *Bus, targetID, commandID string) *FormattedWriter {
return &FormattedWriter{
bus: bus,
targetID: targetID,
commandID: commandID,
}
}
// Write writes the given bytes to the writer.
func (w *FormattedWriter) Write(dt []byte) (int, error) {
// TODO (vladaionescu): Can the timestamp be passed along straight
// from buildkit?
now := w.bus.NowUnixNanos()
w.bus.WriteFormattedLog(&logstream.DeltaFormattedLog{
TargetId: w.targetID,
CommandId: w.commandID,
TimestampUnixNanos: now,
Data: dt,
})
w.bus.WriteFormattedLog(&logstream.DeltaFormattedLog{
TargetId: "_full",
CommandId: w.commandID,
TimestampUnixNanos: now,
Data: dt,
})
return len(dt), nil
}