From 17517393a085040496a7d8381a9eb18f4b5f53b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Sun, 23 Jun 2024 23:24:17 +0200 Subject: [PATCH] FEAT: add option to remove logs created by file logger using logIdentifier. (helpful when changing logger to different one, to clean old files) --- .../kotlin/quanti/com/kotlinlog/file/FileLogger.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kotlinlog/src/main/kotlin/quanti/com/kotlinlog/file/FileLogger.kt b/kotlinlog/src/main/kotlin/quanti/com/kotlinlog/file/FileLogger.kt index ca8b4c1..87f9468 100644 --- a/kotlinlog/src/main/kotlin/quanti/com/kotlinlog/file/FileLogger.kt +++ b/kotlinlog/src/main/kotlin/quanti/com/kotlinlog/file/FileLogger.kt @@ -133,6 +133,17 @@ class FileLogger( companion object { + /** + * Deletes all stored logs in app local memory + */ + fun deleteLogsForIdentifier(appCtx: Context, logIdentifier: String) { + appCtx + .logFilesDir + .listFiles() + .filter { it.name.contains(logIdentifier) } + .filter { it.name.endsWith(".log") } + .forEach { it.delete() } + } /** * Deletes all stored logs in app local memory */