Yokan / rebuild
Course 1 8624561

Logging.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/logging/Logging.kt

implementation36 lines
1package eu.friedcutlet.yokan.services.logging23import eu.friedcutlet.yokan.services.files.LocalFileService4import kotlinx.datetime.plus56/**7 * Public logging surface for the app. Delegates to [LogSink]: stdout always, a bounded in-memory8 * buffer for Settings → Developer, and an opt-in, size-capped log file under9 * [LocalFileService.cacheRoot] (the About screen's `Logs on` setting).10 */11object AppLogger {12    fun info(message: String) = LogSink.write("INFO", message)13    fun warn(message: String) = LogSink.write("WARN", message)14    fun error(message: String) = LogSink.write("ERROR", message)15}1617internal fun redactUrlForLog(url: String, maxLength: Int = 180): String {18    val cleaned = url.trim().substringBefore("#")19    val withoutQuery = cleaned.substringBefore("?")20    val redactedPath = withoutQuery.indexOf("://")21        .takeIf { it >= 0 }22        ?.let { schemeIndex ->23            val pathStart = withoutQuery.indexOf('/', startIndex = schemeIndex + 3)24            if (pathStart < 0) {25                withoutQuery26            } else {27                val origin = withoutQuery.take(pathStart)28                val path = withoutQuery.drop(pathStart)29                val fileName = path.substringAfterLast('/').takeIf { it.isNotBlank() }30                if (path.count { it == '/' } > 1 && fileName != null) "$origin/.../$fileName" else withoutQuery31            }32        }33        ?: withoutQuery34    val redacted = redactedPath + if ("?" in cleaned) "?..." else ""35    return if (redacted.length <= maxLength) redacted else redacted.take((maxLength - 3).coerceAtLeast(0)) + "..."36}37

Search chapters, reference and source filenames.