Captures stdout/stderr log files produced by winsw.
197836
private void addWinsStdoutStderrLog(List<java.util.concurrent.Callable<List<FileContent>>> tasks, final Node node, final SmartLogFetcher logFetcher) {
        final FilePath rootPath = node.getRootPath();
        if (rootPath != null) {
            // rotated log files stored on the disk
            tasks.add(new java.util.concurrent.Callable<List<FileContent>>(){
                public List<FileContent> call() throws Exception {
                    List<FileContent> result = new ArrayList<FileContent>();
                    final Map<String, File> logFiles = logFetcher.forNode(node).getLogFiles(rootPath);
                    for (Map.Entry<String, File> entry : logFiles.entrySet()) {
                        result.add(new FileContent(
                                "nodes/slave/{0}/logs/winsw/{1}", new String[] {node.getNodeName(), entry.getKey()},
                                entry.getValue(), FileListCapComponent.MAX_FILE_SIZE)
                        );
                    }
                    return result;
                }
            });
        }
    }
939636
def report_stderr(host, stderr):
    
    lines = stderr.readlines()
    if lines:
        print("STDERR from {host}:".format(host=host))
        for line in lines:
            print(line.rstrip(), file=sys.stderr)
278614
def captured_output(stream_name):
    
    orig_stdout = getattr(sys, stream_name)
    setattr(sys, stream_name, StreamWrapper.from_stream(orig_stdout))
    try:
        yield getattr(sys, stream_name)
    finally:
        setattr(sys, stream_name, orig_stdout)
850073
@Override
    protected void captureSystemStreams() {
        PrintStream sysOut = System.out;
        PrintStream sysErr = System.err;

        PrintStream trSysOut = systemOut.getOriginalStream();
        PrintStream trSysErr = systemErr.getOriginalStream();

        if (sysOut != trSysOut) {
            throw new ConcurrentModificationException("Someone else has reset or cached System.out");
        }
        if (sysErr != trSysErr) {
            throw new ConcurrentModificationException("Someone else has reset or cached System.err");
        }

        super.captureSystemStreams();
    }
886355
def _close_stdout_stderr_streams(self):
        

        # we don't have tee_file's in headless mode
        if self._stdout_tee.tee_file is not None:
            self._stdout_tee.tee_file.close()
        if self._stderr_tee.tee_file is not None:
            self._stderr_tee.tee_file.close()

        # TODO(adrian): we should close these even in headless mode
        # but in python 2 the read thread doesn't stop on its own
        # for some reason
        self._stdout_tee.close_join()
        self._stderr_tee.close_join()

        if self._cloud:
            # not set in dry run mode
            self._stdout_stream.close()
            self._stderr_stream.close()

        self._output_log.f.close()
        self._output_log = None
81684
def dump_logs(job_queue='run_reach_queue', job_status='RUNNING'):
    """"""
    jobs = get_jobs(job_queue, job_status)
    for job in jobs:
        get_job_log(job, write_file=True)
1197533
private static void dumpOutDebugInfo() {

        LOG.info("Dump debug output");
        Map<String, String> envs = System.getenv();
        for (Map.Entry<String, String> env : envs.entrySet()) {
            LOG.info("System env: key=" + env.getKey() + ", val=" + env.getValue());
            System.out.println("System env: key=" + env.getKey() + ", val="
                    + env.getValue());
        }

        BufferedReader buf = null;
        try {
            String lines = Shell.WINDOWS ? Shell.execCommand("cmd", "/c", "dir") :
                    Shell.execCommand("ls", "-al");
            buf = new BufferedReader(new StringReader(lines));
            String line = "";
            while ((line = buf.readLine()) != null) {
                LOG.info("System CWD content: " + line);
                System.out.println("System CWD content: " + line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            org.apache.hadoop.io.IOUtils.cleanup(LOG, buf);
        }
    }
563670
def reopenOutputFiles():
    
    if not _stdout and not _stderr:
        debug('log', 'told to reopen log files, but log files not set')
        return

    def reopen(name, fileno, *args):
        oldmask = os.umask(0026)
        try:
            f = open(name, 'a+', *args)
        finally:
            os.umask(oldmask)

        os.dup2(f.fileno(), fileno)

    if _stdout:
        reopen(_stdout, sys.stdout.fileno())

    if _stderr:
        reopen(_stderr, sys.stderr.fileno(), 0)
        debug('log', 'opened log %r', _stderr)
1078996
def get_exitcode_stdout_stderr(cmd):
    
    from subprocess import Popen, PIPE
    import shlex
    args = shlex.split(cmd)

    proc = Popen(args, stdout=PIPE, stderr=PIPE)
    out, err = proc.communicate()
    exitcode = proc.returncode

    return exitcode, out, err
826756
def _print_windows(objects, sep, end, file, flush):
    """"""

    h = winapi.INVALID_HANDLE_VALUE

    try:
        fileno = file.fileno()
    except (EnvironmentError, AttributeError):
        pass
    else:
        if fileno == 1:
            h = winapi.GetStdHandle(winapi.STD_OUTPUT_HANDLE)
        elif fileno == 2:
            h = winapi.GetStdHandle(winapi.STD_ERROR_HANDLE)

    encoding = _encoding

    parts = []
    for obj in objects:
        if isinstance(obj, bytes):
            obj = obj.decode(encoding, "replace")
        if not isinstance(obj, text_type):
            obj = text_type(obj)
        parts.append(obj)

    if isinstance(sep, bytes):
        sep = sep.decode(encoding, "replace")
    if not isinstance(sep, text_type):
        raise TypeError

    if isinstance(end, bytes):
        end = end.decode(encoding, "replace")
    if not isinstance(end, text_type):
        raise TypeError

    if end == u"\n":
        end = os.linesep

    text = sep.join(parts) + end
    assert isinstance(text, text_type)

    is_console = True
    if h == winapi.INVALID_HANDLE_VALUE:
        is_console = False
    else:
        # get the default value
        info = winapi.CONSOLE_SCREEN_BUFFER_INFO()
        if not winapi.GetConsoleScreenBufferInfo(h, ctypes.byref(info)):
            is_console = False

    if is_console:
        # make sure we flush before we apply any console attributes
        file.flush()

        # try to force a utf-8 code page, use the output CP if that fails
        cp = winapi.GetConsoleOutputCP()
        try:
            encoding = "utf-8"
            if winapi.SetConsoleOutputCP(65001) == 0:
                encoding = None

            for is_ansi, part in ansi_split(text):
                if is_ansi:
                    ansi_state.apply(h, part)
                else:
                    if encoding is not None:
                        data = part.encode(encoding, _surrogatepass)
                    else:
                        data = _encode_codepage(cp, part)
                    os.write(fileno, data)
        finally:
            # reset the code page to what we had before
            winapi.SetConsoleOutputCP(cp)
    else:
        # try writing bytes first, so in case of Python 2 StringIO we get
        # the same type on all platforms
        try:
            file.write(text.encode("utf-8", _surrogatepass))
        except (TypeError, ValueError):
            file.write(text)

        if flush:
            file.flush()
747376
def dump(self):
        

        # Print out the collectd feedback.
        # This is sent to stdout while other log messages are sent to stderr.
        for k, v in sorted(self._dict.items()):
            print(self.formatter(k, v))

        # Reset each entry to zero
        for k, v in sorted(self._dict.items()):
            self._dict[k] = 0
851037
def print_results(cls, stdout, stderr):
        """"""
        for line in stderr:
            print(line, file=sys.stderr)
        if stdout:
            if stderr:  # blank line to separate stdout from stderr
                print(file=sys.stderr)
            cls._print_stdout(stdout)
        else:
            print(':) No issues found.')
28917
def trace(msg):
    
    if os.environ.get('JARN_TRACE') == '1':
        print('TRACE:', msg, file=sys.stderr)
182551
def _log_to_stderr(self, record):
    
    # emit() is protected by a lock in logging.Handler, so we don't need to
    # protect here again.
    old_stream = self.stream
    self.stream = sys.stderr
    try:
      super(PythonHandler, self).emit(record)
    finally:
      self.stream = old_stream
980810
def _on_process_stderr_ready(self):
        
        try:
            o = self.readAllStandardError()
        except (TypeError, RuntimeError):
            # widget already deleted
            return
        try:
            output = bytes(o).decode(self._encoding)
        except TypeError:
            output = bytes(o.data()).decode(self._encoding)
        for line in output.splitlines():
            self._srv_logger.error(line)
727944
def getOutput(self):
        
        output = self.stdout
        if self.stdout:
            output += '\r\n'
        output += self.stderr
        return output
574975
def _stream_docker_logs(self):
        
        thread = threading.Thread(target=self._stderr_stream_worker)
        thread.start()
        for line in self.docker_client.logs(self.container, stdout=True,
                                            stderr=False, stream=True):
            sys.stdout.write(line)
        thread.join()