Skip to content

Commit

Permalink
Fix a bug when computing the log date from a file name.
Browse files Browse the repository at this point in the history
  • Loading branch information
airxnoor committed Apr 11, 2024
1 parent e577af1 commit 2d275c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

rootProject.group = "com.airthings.lib"
rootProject.version = "0.2.4"
rootProject.version = "0.2.5"

buildscript {
repositories {
Expand Down
12 changes: 8 additions & 4 deletions src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d275c1

Please sign in to comment.