Repository: ktorio/ktor
File: ktor-client/ktor-client-plugins/ktor-client-logging/common/src/io/ktor/client/plugins/logging/Logging.kt (Kotlin)

Code before:
                break
            }
        }

        if (!isBinary) {
            val channel = ByteChannel()

            val copied = client.async {
                channel.writeFully(firstChunk, 0, firstReadSize)
                val copied = body.copyTo(channel)
                channel.flushAndClose()
                copied
            }.await()

            return Triple(isBinary, copied + firstReadSize, channel)
        }

        return Triple(isBinary, contentLength, body)
    }

    suspend fun logRequestBody(
        content: OutgoingContent,
        contentLength: Long?,
        headers: Headers,
        method: HttpMethod,
        body: ByteReadChannel
    ) {
        val (isBinary, size, newBody) = detectIfBinary(body, contentLength, content.contentType, headers)

        if (!isBinary) {
            val contentType = content.contentType
            val charset = if (contentType != null) {
                contentType.charset() ?: Charsets.UTF_8
            } else {
                Charsets.UTF_8
            }

            logger.log(newBody.readRemaining().readText(charset = charset))
            logger.log("--> END ${method.value} ($size-byte body)")
        } else {
            var type = "binary"
            if (headers.contains(HttpHeaders.ContentEncoding)) {
                type = "encoded"
            }

            if (size != null) {
                logger.log("--> END ${method.value} ($type $size-byte body omitted)")
            } else {
                logger.log("--> END ${method.value} ($type body omitted)")
            }
        }

Review comment (suggestion):
I would pass `log: (String) -> Unit` instead, cause you're not using any list functions except add

Code after:
                break
            }
        }

        if (!isBinary) {
            val channel = ByteChannel()

            val copied = client.async {
                channel.writeFully(firstChunk, 0, firstReadSize)
                val copied = body.copyTo(channel)
                channel.flushAndClose()
                copied
            }.await()

            return Triple(isBinary, copied + firstReadSize, channel)
        }

        return Triple(isBinary, contentLength, body)
    }

    suspend fun logRequestBody(
        content: OutgoingContent,
        contentLength: Long?,
        headers: Headers,
        method: HttpMethod,
        logLines: MutableList<String>,
        body: ByteReadChannel
    ) {
        val (isBinary, size, newBody) = detectIfBinary(body, contentLength, content.contentType, headers)

        if (!isBinary) {
            val contentType = content.contentType
            val charset = if (contentType != null) {
                contentType.charset() ?: Charsets.UTF_8
            } else {
                Charsets.UTF_8
            }

            logLines.add(newBody.readRemaining().readText(charset = charset))
            logLines.add("--> END ${method.value} ($size-byte body)")
        } else {
            var type = "binary"
            if (headers.contains(HttpHeaders.ContentEncoding)) {
                type = "encoded"
            }

            if (size != null) {
                logLines.add("--> END ${method.value} ($type $size-byte body omitted)")
            } else {
                logLines.add("--> END ${method.value} ($type body omitted)")
            }