MCPcopy Create free account
hub / github.com/containerd/nerdctl / Encode

Function Encode

pkg/logging/jsonfile/jsonfile.go:70–96  ·  view source on GitHub ↗
(stdout <-chan string, stderr <-chan string, writer io.Writer)

Source from the content-addressed store, hash-verified

68}
69
70func Encode(stdout <-chan string, stderr <-chan string, writer io.Writer) error {
71 enc := json.NewEncoder(writer)
72 var encMu sync.Mutex
73 var wg sync.WaitGroup
74 wg.Add(2)
75 f := func(dataChan <-chan string, name string) {
76 defer wg.Done()
77 e := &Entry{
78 Stream: name,
79 }
80 for logEntry := range dataChan {
81 e.Log = logEntry
82 e.Time = time.Now().UTC()
83 encMu.Lock()
84 encErr := enc.Encode(e)
85 encMu.Unlock()
86 if encErr != nil {
87 log.L.WithError(encErr).Errorf("failed to encode JSON")
88 return
89 }
90 }
91 }
92 go f(stdout, "stdout")
93 go f(stderr, "stderr")
94 wg.Wait()
95 return nil
96}
97
98func writeEntry(e *Entry, stdout, stderr io.Writer, refTime time.Time, timestamps bool, since string, until string) error {
99 output := []byte{}

Callers 1

ProcessMethod · 0.92

Calls 4

AddMethod · 0.80
EncodeMethod · 0.80
LockMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…