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

Function writeEntry

pkg/logging/jsonfile/jsonfile.go:98–153  ·  view source on GitHub ↗
(e *Entry, stdout, stderr io.Writer, refTime time.Time, timestamps bool, since string, until string)

Source from the content-addressed store, hash-verified

96}
97
98func writeEntry(e *Entry, stdout, stderr io.Writer, refTime time.Time, timestamps bool, since string, until string) error {
99 output := []byte{}
100
101 if since != "" {
102 ts, err := timestamp.GetTimestamp(since, refTime)
103 if err != nil {
104 return fmt.Errorf("invalid value for \"since\": %w", err)
105 }
106 v := strings.Split(ts, ".")
107 i, err := strconv.ParseInt(v[0], 10, 64)
108 if err != nil {
109 return err
110 }
111 if e.Time.Before(time.Unix(i, 0)) {
112 return nil
113 }
114 }
115
116 if until != "" {
117 ts, err := timestamp.GetTimestamp(until, refTime)
118 if err != nil {
119 return fmt.Errorf("invalid value for \"until\": %w", err)
120 }
121 v := strings.Split(ts, ".")
122 i, err := strconv.ParseInt(v[0], 10, 64)
123 if err != nil {
124 return err
125 }
126 if e.Time.After(time.Unix(i, 0)) {
127 return nil
128 }
129 }
130
131 if timestamps {
132 output = append(output, []byte(e.Time.Format(time.RFC3339Nano))...)
133 output = append(output, ' ')
134 }
135
136 output = append(output, []byte(e.Log)...)
137
138 var writeTo io.Writer
139 switch e.Stream {
140 case "stdout":
141 writeTo = stdout
142 case "stderr":
143 writeTo = stderr
144 default:
145 log.L.Errorf("unknown stream name %q, entry=%+v", e.Stream, e)
146 }
147
148 if writeTo != nil {
149 _, err := writeTo.Write(output)
150 return err
151 }
152 return nil
153}
154
155func Decode(stdout, stderr io.Writer, r io.Reader, timestamps bool, since string, until string) ([]byte, error) {

Callers 1

DecodeFunction · 0.85

Calls 2

GetTimestampFunction · 0.92
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…