<commit_before>package eu.nets.utils.jetty.embedded;

import org.slf4j.LoggerFactory;

import java.io.PrintStream;

import static com.google.common.base.CharMatcher.anyOf;
import static com.google.common.base.Splitter.on;


/**
 * Shameless ripoff from stackoverflow.com
 */
public class StdoutRedirect {

    public static void tieSystemOutAndErrToLog() {

        // Be sure log4j has been initialized here.
        //  this shameless ripoff causes an infinite loop ehn log4j has not been properly initialized...
        //log4j -> logs to standard-err when it finds no appenders, standard err has been redirected using slf 4j
        //and here we go...
        System.setOut(createLoggingProxy(System.out));
        System.setErr(createLoggingProxy(System.err));
    }

    private static PrintStream createLoggingProxy(final PrintStream realPrintStream) {
        return new PrintStream(realPrintStream) {
            public void print(final String string) {
                Iterable<String> lines = on(anyOf("\r\n")).split(string);
                for (String line : lines) {
                    LoggerFactory.getLogger("stdout").info(line);
                }
            }

            @Override
            public void print(Object obj) {
                print(String.valueOf(obj));
            }

            @Override
            public void println(String s) {
                print(s);<commit_msg>Made the stdout/stderr capture properly differentiate between stdout/stderr<commit_after>package eu.nets.utils.jetty.embedded;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.OutputStream;
import java.io.PrintStream;

import static com.google.common.base.CharMatcher.anyOf;
import static com.google.common.base.Splitter.on;


/**
 * Not-entirely Shameless ripoff from stackoverflow.com
 */
public class StdoutRedirect {

    public static void tieSystemOutAndErrToLog() {

        // Be sure log4j has been initialized here, which is always the case for embedded-jetty.
        //  this shameless ripoff causes an infinite loop ehn log4j has not been properly initialized...
        //log4j -> logs to standard-err when it finds no appenders, standard err has been redirected using slf 4j
        //and here we go...
        System.setOut(createLoggingProxy(System.out, "stdout", true));
        System.setErr(createLoggingProxy(System.err, "stderr", false));
    }


    private static PrintStream createLoggingProxy(final PrintStream realPrintStream, final String stream, final boolean stdout) {
        return new PrintStream(realPrintStream) {

            private Logger logger = LoggerFactory.getLogger(stdout ? "stdout" : "stderr");


            public void print(final String string) {
                Iterable<String> lines = on(anyOf("\r\n")).split(string);
                for (String line : lines) {
                    if (stdout)
                        logger.info(line);
                    else
                        logger.warn(line);
                }
            }

            @Override
            public void print(Object obj) {
                print(String.valueOf(obj));
            }

            @Override
            public void println(String s) {
                print(s);
{'fraction_non_alphanumeric': 0.08919753086419753, 'fraction_numerical': 0.0033950617283950617, 'mean_word_length': 2.2345309381237524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559882', 'n_tokens_mistral': 879, 'n_tokens_neox': 835, 'n_words': 240}