From 2d275c103f2164fcd8024fbd91a5f3db55024bac Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Thu, 11 Apr 2024 10:38:07 +0200 Subject: [PATCH] Fix a bug when computing the log date from a file name. --- CHANGES.txt | 4 ++++ build.gradle.kts | 2 +- .../kotlin/com/airthings/lib/logging/LogDate.kt | 12 ++++++++---- .../lib/logging/facility/FileLoggerFacility.kt | 5 +++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ef9a3c1..cf2a40a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +0.2.5 - April 11, 2024 +• Fix a bug when computing the log date from a file name. +• Expose `FileLoggerFacility.baseFolder` property to public use. + 0.2.4 - April 11, 2024 • Fix a bug where the wrong platform was reported. • Make it easier to debug the Android/JVM folder scanning. diff --git a/build.gradle.kts b/build.gradle.kts index 2313187..1e371c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ */ rootProject.group = "com.airthings.lib" -rootProject.version = "0.2.4" +rootProject.version = "0.2.5" buildscript { repositories { diff --git a/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt b/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt index 30a7538..572fe95 100644 --- a/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt +++ b/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt @@ -106,22 +106,26 @@ fun String.asLogDate(separator: Char?): LogDate? { } val dateAsIntValue = if (separator == null) { - toIntOrNull() + fileNameWithoutExtension.toIntOrNull() } else { - replace("$separator", "").toIntOrNull() + fileNameWithoutExtension.replace("$separator", "").toIntOrNull() } if (dateAsIntValue == null) { return null } - val dateAsStringValue = "$dateAsIntValue".padStart(expectedLength, '0') + val dateAsStringValue = dateAsIntValue.padded(expectedLength) val year = dateAsStringValue.substring(0, 4).toIntOrNull() ?: return null val month = dateAsStringValue.substring(4, 6).toIntOrNull() ?: return null val day = dateAsStringValue.substring(6, 8).toIntOrNull() ?: return null - return LogDate(year, month, day) + return LogDate( + year = year, + month = month, + day = day, + ) } /** diff --git a/src/commonMain/kotlin/com/airthings/lib/logging/facility/FileLoggerFacility.kt b/src/commonMain/kotlin/com/airthings/lib/logging/facility/FileLoggerFacility.kt index d63b599..8f93aaa 100644 --- a/src/commonMain/kotlin/com/airthings/lib/logging/facility/FileLoggerFacility.kt +++ b/src/commonMain/kotlin/com/airthings/lib/logging/facility/FileLoggerFacility.kt @@ -17,6 +17,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@file:Suppress("unused", "MemberVisibilityCanBePrivate") + package com.airthings.lib.logging.facility import co.touchlab.stately.concurrency.AtomicReference @@ -45,10 +47,9 @@ import kotlinx.coroutines.launch * @param coroutineScope A coroutine scope to run blocking i/o on. * @param notifier An optional implementation of [PlatformFileInputOutputNotifier]. */ -@Suppress("unused") class FileLoggerFacility( private val minimumLogLevel: LogLevel, - private val baseFolder: String, + val baseFolder: String, private val coroutineScope: CoroutineScope, private val notifier: PlatformFileInputOutputNotifier?, ) : LoggerFacility {