code: func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
  	wf := ioutils.NewWriteFlusher(w)
  	defer wf.Close()
  
  	wf.Flush()
  
  	outStream := io.Writer(wf)
  	errStream := outStream
  	sysErrStream := errStream
  	if mux {
  		sysErrStream = stdcopy.NewStdWriter(outStream, stdcopy.Systemerr)
  		errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
  		outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
  	}
  
  	for {
  		msg, ok := <-msgs
  		if !ok {
  			return
  		}
  		// check if the message contains an error. if so, write that error
  		// and exit
  		if msg.Err != nil {
  			fmt.Fprintf(sysErrStream, "Error grabbing logs: %v\n", msg.Err)
  			continue
  		}
  		logLine := msg.Line
  		if config.Details {
  			logLine = append(attrsByteSlice(msg.Attrs), ' ')
  			logLine = append(logLine, msg.Line...)
  		}
  		if config.Timestamps {
  			logLine = append([]byte(msg.Timestamp.Format(jsonmessage.RFC3339NanoFixed)+" "), logLine...)
  		}
  		if msg.Source == "stdout" && config.ShowStdout {
  			outStream.Write(logLine)
  		}
  		if msg.Source == "stderr" && config.ShowStderr {
  			errStream.Write(logLine)
  		}
  	}
  }
docs: // WriteLogStream writes an encoded byte stream of log messages from the
  // messages channel, multiplexing them with a stdcopy.Writer if mux is true