<commit_before>package net.dean.jraw.http

import net.dean.jraw.JrawUtils
import net.dean.jraw.http.SimpleHttpLogger.Companion.LINE_LENGTH
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.Buffer
import java.io.PrintStream
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

/**
 * Bare-bones implementation of HttpLogger
 *
 * This logger will print the request's method ("GET", "POST", etc.) and URL, as well as the response's base media type
 * (e.g. "application/json") and body. The response line will be truncated to 100 lines (the value of [LINE_LENGTH]).
 *
 * Here's an example of the 12th request logged by a [SimpleHttpLogger]
 *
 * ```
 * [12 ->] POST https://oauth.reddit.com/foo?bar=baz
 *         form: form=foo
 *               abc=123
 * [12 <-] 200 application/json: '{"foo":"bar"}'
 * ```
 *
 * @see LINE_LENGTH
 */
class SimpleHttpLogger(val out: PrintStream = System.out) : HttpLogger {
    private val counter: AtomicInteger = AtomicInteger()
    private val lock = Any()

    override fun request(r: HttpRequest, sent: Date): HttpLogger.Tag {
        val id = counter.getAndIncrement()

        synchronized(lock) {
            val tag = "[$id ->]"

            out.println("$tag ${r.method} ${r.url}")

            val form = parseForm(r)
            if (!form.isEmpty()) {
                logMap(
                    baseIndentLength = tag.length,
                    header = "form:",
                    pairs = form
                )
            }
        }

        return HttpLogger.Tag(id, sent)
    }

    override fun response(tag: HttpLogger.Tag, res: HttpResponse) {
        val contentType = MediaType.parse(res.contentType)!!<commit_msg>Make SimpleHttpLogger start at 1 instead of 0<commit_after>package net.dean.jraw.http

import net.dean.jraw.JrawUtils
import net.dean.jraw.http.SimpleHttpLogger.Companion.LINE_LENGTH
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.Buffer
import java.io.PrintStream
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

/**
 * Bare-bones implementation of HttpLogger
 *
 * This logger will print the request's method ("GET", "POST", etc.) and URL, as well as the response's base media type
 * (e.g. "application/json") and body. The response line will be truncated to 100 lines (the value of [LINE_LENGTH]).
 *
 * Here's an example of the 12th request logged by a [SimpleHttpLogger]
 *
 * ```
 * [12 ->] POST https://oauth.reddit.com/foo?bar=baz
 *         form: form=foo
 *               abc=123
 * [12 <-] 200 application/json: '{"foo":"bar"}'
 * ```
 *
 * @see LINE_LENGTH
 */
class SimpleHttpLogger(val out: PrintStream = System.out) : HttpLogger {
    private val counter: AtomicInteger = AtomicInteger(1)
    private val lock = Any()

    override fun request(r: HttpRequest, sent: Date): HttpLogger.Tag {
        val id = counter.getAndIncrement()

        synchronized(lock) {
            val tag = "[$id ->]"

            out.println("$tag ${r.method} ${r.url}")

            val form = parseForm(r)
            if (!form.isEmpty()) {
                logMap(
                    baseIndentLength = tag.length,
                    header = "form:",
                    pairs = form
                )
            }
        }

        return HttpLogger.Tag(id, sent)
    }

    override fun response(tag: HttpLogger.Tag, res: HttpResponse) {
        val contentType = MediaType.parse(res.contentType)!!
{'fraction_non_alphanumeric': 0.11966308451931455, 'fraction_numerical': 0.010746442056346209, 'mean_word_length': 2.48582995951417, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5829039', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1001, 'n_words': 282}