package eu.friedcutlet.yokan.services.logging import eu.friedcutlet.yokan.services.files.LocalFileService import kotlinx.datetime.plus /** * Public logging surface for the app. Delegates to [LogSink]: stdout always, a bounded in-memory * buffer for Settings → Developer, and an opt-in, size-capped log file under * [LocalFileService.cacheRoot] (the About screen's `Logs on` setting). */ object AppLogger { fun info(message: String) = LogSink.write("INFO", message) fun warn(message: String) = LogSink.write("WARN", message) fun error(message: String) = LogSink.write("ERROR", message) } internal fun redactUrlForLog(url: String, maxLength: Int = 180): String { val cleaned = url.trim().substringBefore("#") val withoutQuery = cleaned.substringBefore("?") val redactedPath = withoutQuery.indexOf("://") .takeIf { it >= 0 } ?.let { schemeIndex -> val pathStart = withoutQuery.indexOf('/', startIndex = schemeIndex + 3) if (pathStart < 0) { withoutQuery } else { val origin = withoutQuery.take(pathStart) val path = withoutQuery.drop(pathStart) val fileName = path.substringAfterLast('/').takeIf { it.isNotBlank() } if (path.count { it == '/' } > 1 && fileName != null) "$origin/.../$fileName" else withoutQuery } } ?: withoutQuery val redacted = redactedPath + if ("?" in cleaned) "?..." else "" return if (redacted.length <= maxLength) redacted else redacted.take((maxLength - 3).coerceAtLeast(0)) + "..." }