@@ -17,6 +17,7 @@ import (
17
17
18
18
"github.com/creack/pty"
19
19
"github.com/google/uuid"
20
+ "github.com/sirupsen/logrus"
20
21
"golang.org/x/sys/unix"
21
22
"golang.org/x/xerrors"
22
23
@@ -62,7 +63,7 @@ func (m *Mux) Start(cmd *exec.Cmd, options TermOptions) (alias string, err error
62
63
}
63
64
alias = uid .String ()
64
65
65
- term , err := newTerm (pty , cmd , options )
66
+ term , err := newTerm (alias , pty , cmd , options )
66
67
if err != nil {
67
68
pty .Close ()
68
69
return "" , err
@@ -188,7 +189,7 @@ func (term *Term) shutdownProcessImmediately() error {
188
189
// For now we assume an average of five terminals per workspace, which makes this consume 1MiB of RAM.
189
190
const terminalBacklogSize = 256 << 10
190
191
191
- func newTerm (pty * os.File , cmd * exec.Cmd , options TermOptions ) (* Term , error ) {
192
+ func newTerm (alias string , pty * os.File , cmd * exec.Cmd , options TermOptions ) (* Term , error ) {
192
193
token , err := uuid .NewRandom ()
193
194
if err != nil {
194
195
return nil , err
@@ -207,9 +208,11 @@ func newTerm(pty *os.File, cmd *exec.Cmd, options TermOptions) (*Term, error) {
207
208
PTY : pty ,
208
209
Command : cmd ,
209
210
Stdout : & multiWriter {
210
- timeout : timeout ,
211
- listener : make (map [* multiWriterListener ]struct {}),
212
- recorder : recorder ,
211
+ timeout : timeout ,
212
+ listener : make (map [* multiWriterListener ]struct {}),
213
+ recorder : recorder ,
214
+ logStdout : options .LogToStdout ,
215
+ logLabel : alias ,
213
216
},
214
217
Annotations : options .Annotations ,
215
218
title : options .Title ,
@@ -245,6 +248,9 @@ type TermOptions struct {
245
248
246
249
// Title describes the terminal title.
247
250
Title string
251
+
252
+ // LogToStdout forwards the terminal's stdout to supervisor's stdout
253
+ LogToStdout bool
248
254
}
249
255
250
256
// Term is a pseudo-terminal
@@ -312,6 +318,9 @@ type multiWriter struct {
312
318
// ring buffer to record last 256kb of pty output
313
319
// new listener is initialized with the latest recodring first
314
320
recorder * RingBuffer
321
+
322
+ logStdout bool
323
+ logLabel string
315
324
}
316
325
317
326
var (
@@ -424,6 +433,12 @@ func (mw *multiWriter) Write(p []byte) (n int, err error) {
424
433
defer mw .mu .Unlock ()
425
434
426
435
mw .recorder .Write (p )
436
+ if mw .logStdout {
437
+ log .WithFields (logrus.Fields {
438
+ "terminalOutput" : true ,
439
+ "label" : mw .logLabel ,
440
+ }).Info (string (p ))
441
+ }
427
442
428
443
for lstr := range mw .listener {
429
444
if lstr .closed {
0 commit comments