Skip to content

Commit 55d8ed4

Browse files
committed
[executor] Support separate stdout/stderr settings in all tasks
1 parent 4ca99ae commit 55d8ed4

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

executor/executable/basictaskcommon.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,16 @@ func (t *basicTaskBase) startBasicTask() (err error) {
7373
var stdoutBuf, stderrBuf bytes.Buffer
7474
var stdout, stderr io.Writer
7575

76-
if t.Tci.Log == nil {
76+
if t.Tci.Stdout == nil {
7777
none := "none"
78-
t.Tci.Log = &none
78+
t.Tci.Stdout = &none
7979
}
80-
switch *t.Tci.Log {
80+
if t.Tci.Stderr == nil {
81+
none := "none"
82+
t.Tci.Stderr = &none
83+
}
84+
85+
switch *t.Tci.Stdout {
8186
case "stdout":
8287
stdoutLog := log.WithPrefix("task-stdout").
8388
WithField("level", infologger.IL_Support).
@@ -86,38 +91,49 @@ func (t *basicTaskBase) startBasicTask() (err error) {
8691
WithField("task", t.ti.Name).
8792
WithField("nohooks", true).
8893
WriterLevel(logrus.TraceLevel)
89-
stderrLog := log.WithPrefix("task-stderr").
94+
95+
// Each of these multiwriters will push incoming lines to a buffer as well as the logger
96+
stdout = io.MultiWriter(stdoutLog, &stdoutBuf)
97+
98+
case "all":
99+
stdoutLog := log.WithPrefix("task-stdout").
90100
WithField("level", infologger.IL_Support).
91101
WithField("partition", t.knownEnvironmentId.String()).
92102
WithField("detector", t.knownDetector).
93103
WithField("task", t.ti.Name).
94-
WithField("nohooks", true).
95104
WriterLevel(logrus.TraceLevel)
96-
97-
// Each of these multiwriters will push incoming lines to a buffer as well as the logger
98105
stdout = io.MultiWriter(stdoutLog, &stdoutBuf)
99-
stderr = io.MultiWriter(stderrLog, &stderrBuf)
100106

101-
case "all":
102-
stdoutLog := log.WithPrefix("task-stdout").
107+
default:
108+
// Nothing goes to the log, we go straight to the buffer
109+
stdout = &stdoutBuf
110+
}
111+
112+
switch *t.Tci.Stderr {
113+
case "stdout":
114+
stderrLog := log.WithPrefix("task-stderr").
103115
WithField("level", infologger.IL_Support).
104116
WithField("partition", t.knownEnvironmentId.String()).
105117
WithField("detector", t.knownDetector).
106118
WithField("task", t.ti.Name).
119+
WithField("nohooks", true).
107120
WriterLevel(logrus.TraceLevel)
121+
122+
// Each of these multiwriters will push incoming lines to a buffer as well as the logger
123+
stderr = io.MultiWriter(stderrLog, &stderrBuf)
124+
125+
case "all":
108126
stderrLog := log.WithPrefix("task-stderr").
109127
WithField("level", infologger.IL_Support).
110128
WithField("partition", t.knownEnvironmentId.String()).
111129
WithField("detector", t.knownDetector).
112130
WithField("task", t.ti.Name).
113131
WriterLevel(logrus.TraceLevel)
114132

115-
stdout = io.MultiWriter(stdoutLog, &stdoutBuf)
116133
stderr = io.MultiWriter(stderrLog, &stderrBuf)
117134

118135
default:
119136
// Nothing goes to the log, we go straight to the buffer
120-
stdout = &stdoutBuf
121137
stderr = &stderrBuf
122138
}
123139

executor/executable/controllabletask.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@ func (t *ControllableTask) Launch() error {
168168
"level": infologger.IL_Devel,
169169
}))
170170

171-
if t.Tci.Log == nil {
171+
if t.Tci.Stdout == nil {
172172
none := "none"
173-
t.Tci.Log = &none
173+
t.Tci.Stdout = &none
174174
}
175-
switch *t.Tci.Log {
175+
if t.Tci.Stderr == nil {
176+
none := "none"
177+
t.Tci.Stderr = &none
178+
}
179+
180+
switch *t.Tci.Stdout {
176181
case "stdout":
177182
go func() {
178183
entry := log.WithPrefix("task-stdout").
@@ -188,34 +193,43 @@ func (t *ControllableTask) Launch() error {
188193
_, errStdout = io.Copy(writer, stdoutIn)
189194
writer.Flush()
190195
}()
196+
case "all":
191197
go func() {
192-
entry := log.WithPrefix("task-stderr").
198+
entry := log.WithPrefix("task-stdout").
193199
WithField("level", infologger.IL_Support).
194200
WithField("partition", t.knownEnvironmentId.String()).
195201
WithField("detector", t.knownDetector).
196-
WithField("task", t.ti.Name).
197-
WithField("nohooks", true)
202+
WithField("task", t.ti.Name)
198203
writer := &logger.SafeLogrusWriter{
199204
Entry: entry,
200-
PrintFunc: entry.Warn,
205+
PrintFunc: entry.Debug,
201206
}
202-
_, errStderr = io.Copy(writer, stderrIn)
207+
_, errStdout = io.Copy(writer, stdoutIn)
203208
writer.Flush()
204209
}()
205-
case "all":
210+
default:
206211
go func() {
207-
entry := log.WithPrefix("task-stdout").
212+
_, errStdout = io.Copy(io.Discard, stdoutIn)
213+
}()
214+
}
215+
216+
switch *t.Tci.Stderr {
217+
case "stdout":
218+
go func() {
219+
entry := log.WithPrefix("task-stderr").
208220
WithField("level", infologger.IL_Support).
209221
WithField("partition", t.knownEnvironmentId.String()).
210222
WithField("detector", t.knownDetector).
211-
WithField("task", t.ti.Name)
223+
WithField("task", t.ti.Name).
224+
WithField("nohooks", true)
212225
writer := &logger.SafeLogrusWriter{
213226
Entry: entry,
214-
PrintFunc: entry.Debug,
227+
PrintFunc: entry.Warn,
215228
}
216-
_, errStdout = io.Copy(writer, stdoutIn)
229+
_, errStderr = io.Copy(writer, stderrIn)
217230
writer.Flush()
218231
}()
232+
case "all":
219233
go func() {
220234
entry := log.WithPrefix("task-stderr").
221235
WithField("level", infologger.IL_Support).
@@ -230,9 +244,6 @@ func (t *ControllableTask) Launch() error {
230244
writer.Flush()
231245
}()
232246
default:
233-
go func() {
234-
_, errStdout = io.Copy(io.Discard, stdoutIn)
235-
}()
236247
go func() {
237248
_, errStderr = io.Copy(io.Discard, stderrIn)
238249
}()

0 commit comments

Comments
 (0)