// consoleOutput is an override for the console.log and console.error methods to
// stream the output into the configured output stream instead of stdout.
509397
func consoleOutput(call otto.FunctionCall) otto.Value {
	output := []string{"JS:> "}
	for _, argument := range call.ArgumentList {
		output = append(output, fmt.Sprintf("%v", argument))
	}
	fmt.Fprintln(os.Stderr, strings.Join(output, " "))
	return otto.Value{}
}
705714
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner bootstrapper.CommandRunner, lines int) error {
	cmds := logCommands(r, bs, lines, false)

	// These are not technically logs, but are useful to have in bug reports.
	cmds["kernel"] = "uptime && uname -a"

	names := []string{}
	for k := range cmds {
		names = append(names, k)
	}
	sort.Strings(names)

	failed := []string{}
	for i, name := range names {
		if i > 0 {
			console.OutLn("")
		}
		console.OutLn("==> %s <==", name)
		var b bytes.Buffer
		err := runner.CombinedOutputTo(cmds[name], &b)
		if err != nil {
			glog.Errorf("failed: %v", err)
			failed = append(failed, name)
			continue
		}
		scanner := bufio.NewScanner(&b)
		for scanner.Scan() {
			console.OutLn(scanner.Text())
		}
	}
	if len(failed) > 0 {
		return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", "))
	}
	return nil
}
334387
func (logger *Logger) ResetOutput() {
	logger.outputMutex.Lock()
	logger.outputs = make([]*loggerOutputWrapper, 0)
	logger.outputMutex.Unlock()
}
1232837
func (l *ConsoleLogger) output(msg *Message) {
	buf := []byte{}
	buf = append(buf, msg.time.Format(l.timeFormat)...)
	if l.prefix != "" {
		buf = append(buf, ' ')
		buf = append(buf, l.prefix...)
	}
	buf = append(buf, ' ')
	buf = append(buf, l.levels[msg.level]...)
	buf = append(buf, ' ')
	buf = append(buf, msg.m...)
	if len(msg.m) > 0 && msg.m[len(msg.m)-1] != '\n' {
		buf = append(buf, '\n')
	}
	l.out.Write(buf)
}
408823
func (p *Printer) SetOutput(writers ...io.Writer) *Printer {
	var w io.Writer
	if l := len(writers); l == 0 {
		return p
	} else if l == 1 {
		w = writers[0]
	} else {
		w = io.MultiWriter(writers...)
	}

	p.mu.Lock()
	p.Output = w
	p.IsTerminal = terminal.IsTerminal(w)
	p.mu.Unlock()
	return p
}
1249283
func (cfg *cloudConfig) SetOutput(kind OutputKind, stdout, stderr string) {
	out, _ := cfg.attrs["output"].(map[string]interface{})
	if out == nil {
		out = make(map[string]interface{})
	}

	if stderr == "" {
		out[string(kind)] = stdout
	} else {
		out[string(kind)] = []string{stdout, stderr}
	}

	cfg.SetAttr("output", out)
}
337699
func (cfg *cloudConfig) Output(kind OutputKind) (stdout, stderr string) {
	if out, ok := cfg.attrs["output"].(map[string]interface{}); ok {
		switch out := out[string(kind)].(type) {
		case string:
			stdout = out
		case []string:
			stdout, stderr = out[0], out[1]
		}
	}

	return stdout, stderr
}
1307395
func (p *Printer) AddOutput(writers ...io.Writer) *Printer {
	p.mu.Lock()
	defer p.mu.Unlock()

	for _, w := range writers {
		// set is terminal to false
		// if at least one of the writers
		// is not a terminal-based.
		if !terminal.IsTerminal(w) {
			p.IsTerminal = false
			break
		}
	}

	w := io.MultiWriter(append(writers, p.Output)...)
	p.Output = w
	return p

	// p.mu.Lock()
	// oldW := p.Output
	// newW := io.MultiWriter(writers...)
	// p.Output = writerFunc(func(p []byte) (n int, err error) {
	// 	n, err = oldW.Write(p)
	// 	if err != nil {
	// 		return
	// 	}
	// 	if n != len(p) {
	// 		err = io.ErrShortWrite
	// 		return
	// 	}
	// 	return newW.Write(p)
	// })
	// p.mu.Unlock()
}
1160554
func NewErrorOutput(format string, v ...interface{}) OutputModel {
	return OutputModel{
		Error: fmt.Sprintf(format, v...),
	}
}
943128
func FullOutput(c *exec.Cmd) (stdout []byte, stderr []byte, code int, err error) {
	var outbuf, errbuf bytes.Buffer

	c.Stdout = &outbuf
	c.Stderr = &errbuf

	if runtime.GOOS == "windows" {
		// For powershell, if running a script we need to execute it with a -File option
		// otherwise the return code will get lost
		if len(c.Args) == 2 && strings.Contains(c.Args[0], "powershell.exe") && strings.HasSuffix(c.Args[1], ".ps1") {
			c.Args = []string{c.Args[0], "-File", c.Args[1]}
		}
	}
	if err := c.Start(); err != nil {
		return nil, nil, 0, err
	}

	err = c.Wait()
	code, err = exitCode(err)
	stdout = outbuf.Bytes()
	stderr = errbuf.Bytes()

	return stdout, stderr, code, err
}
594348
func (s *DescribeExecutionOutput) SetOutput(v string) *DescribeExecutionOutput {
	s.Output = &v
	return s
}
1051152
func (s *AddApplicationOutputInput) SetOutput(v *Output) *AddApplicationOutputInput {
	s.Output = v
	return s
}
589561
func (l *Logger) SetOutput(w io.Writer) {
	l.mu.Lock()
	defer l.mu.Unlock()
	l.lg.SetOutput(w)
}
505580
func (api *API) ConsoleWrite(consoleID, command string) error {
	var response map[string]int
	var request = []string{"console.write", api.Token, consoleID, command}
	err := api.request(&request, &response)
	if err != nil {
		return err
	}
	if response["wrote"] != len(command) {
		return errors.New("Wrote length != command length")
	}
	return nil
}
1056609
func (c *LogCmd) Output() ([]byte, error) {
	st := time.Now()
	data, err := c.Cmd.Output()
	if err != nil {
		ee, ok := err.(*exec.ExitError)
		if ok {
			c.log(st, err, ee.Stderr)
			return data, err
		}
	}
	c.log(st, err, nil)
	return data, err
}
321519
function consoleOutput(param, record) {
  var _console;

  (_console = console)[record.level >= Level.ERROR ? 'error' : 'log'].apply(_console, param);
}
1131170
func formatShellOutput(o string) {
	for _, line := range strings.Split(o, "\n") {
		if line != "" {
			beeLogger.Log.Infof("|> %s", line)
		}
	}
}