cmd := exec.Command("ls", "-l") stdout, _ := cmd.StdoutPipe() streamFormatter := utils.StreamFormatter{ Out: os.Stdout, IsTerminal: true, } writer := io.MultiWriter(streamFormatter, os.Stdout) go func() { if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, err) } }() sc := bufio.NewScanner(stdout) for sc.Scan() { fmt.Fprintln(writer, sc.Text()) }
logWriter := utils.StreamFormatter{ Out: os.Stderr, IsTerminal: true, } log.SetOutput(logWriter) log.SetFormatter(&log.JSONFormatter{})In this example, the log formatter is set to JSON and the output is sent to `os.Stderr` with colorization if running in a terminal.