<commit_before>package com.github.dreamhead.moco.monitor;

import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.Response;
import com.github.dreamhead.moco.dumper.Dumper;
import com.github.dreamhead.moco.dumper.HttpRequestDumper;
import com.github.dreamhead.moco.dumper.HttpResponseDumper;

import java.io.PrintWriter;
import java.io.StringWriter;

public class DefaultLogFormatter implements LogFormatter {
    private final Dumper<Request> requestDumper = new HttpRequestDumper();
    private final Dumper<Response> responseDumper = new HttpResponseDumper();

    @Override
    public String format(final Request request) {
        return String.format("Request received:\n\n%s\n", requestDumper.dump(request));
    }

    @Override
    public String format(final Response response) {
        return String.format("Response return:\n\n%s\n", responseDumper.dump(response));
    }

    @Override
    public String format(final Throwable e) {
        return String.format("Exception thrown:\n\n%s\n", stackTraceToString(e));
    }

    private String stackTraceToString(final Throwable e) {
        StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        return writer.toString();
    }
}<commit_msg>selected request dumper in log formatter<commit_after>package com.github.dreamhead.moco.monitor;

import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.HttpResponse;
import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.Response;
import com.github.dreamhead.moco.SocketRequest;
import com.github.dreamhead.moco.SocketResponse;
import com.github.dreamhead.moco.dumper.Dumper;
import com.github.dreamhead.moco.dumper.HttpRequestDumper;
import com.github.dreamhead.moco.dumper.HttpResponseDumper;
import com.github.dreamhead.moco.dumper.SocketRequestDumper;
import com.github.dreamhead.moco.dumper.SocketResponseDumper;

import java.io.PrintWriter;
import java.io.StringWriter;

public class DefaultLogFormatter implements LogFormatter {
    @Override
    public String format(final Request request) {
        return String.format("Request received:\n\n%s\n", requestDumper(request).dump(request));
    }

    @Override
    public String format(final Response response) {
        return String.format("Response return:\n\n%s\n", responseDumper(response).dump(response));
    }

    @Override
    public String format(final Throwable e) {
        return String.format("Exception thrown:\n\n%s\n", stackTraceToString(e));
    }

    private String stackTraceToString(final Throwable e) {
        StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        return writer.toString();
    }

    private Dumper<Request> requestDumper(final Request request) {
        if (request instanceof HttpRequest) {
            return new HttpRequestDumper();
        }

        if (request instanceof SocketRequest) {
            return new SocketRequestDumper();
        }

        throw new IllegalArgumentException("Unknown request type:" + request.getClass());
    }

    private Dumper<Response> responseDumper(final Response response) {
        if (response instanceof HttpResponse) {
            return new HttpResponseDumper();
        }

        if (response instanceof SocketResponse) {
            return new SocketResponseDumper();
        }

        throw new IllegalArgumentException("Unknown response type:" + response.getClass());
    }
}
{'fraction_non_alphanumeric': 0.10025780578630765, 'fraction_numerical': 0.0, 'mean_word_length': 3.8432732316227463, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1698231', 'n_tokens_mistral': 979, 'n_tokens_neox': 948, 'n_words': 207}