Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Dec 25, 2024
1 parent 90c272e commit 34b7950
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 0 additions & 2 deletions library/loggers/lumberjack/file/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ kotlin {
implementation(project(":lumberjack:core"))
implementation(project(":lumberjack:implementations:lumberjack"))

implementation(deps.moko.parcelize)

}
}
}
Expand Down
1 change: 1 addition & 0 deletions library/loggers/timber/file/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
// ------------------------

implementation(kotlinx.coroutines.core)
implementation(kotlinx.io.core)

// ------------------------
// Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.michaelflisar.lumberjack.loggers.timber.file

import com.michaelflisar.lumberjack.core.classes.Level
import com.michaelflisar.lumberjack.core.interfaces.IFileConverter
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import dev.icerock.moko.parcelize.IgnoredOnParcel
import dev.icerock.moko.parcelize.Parcelize
import java.util.regex.Pattern

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import android.content.Context
import android.os.Parcelable
import com.michaelflisar.lumberjack.core.interfaces.IFileConverter
import com.michaelflisar.lumberjack.core.interfaces.IFileLoggingSetup
import dev.icerock.moko.parcelize.IgnoredOnParcel
import dev.icerock.moko.parcelize.Parcelize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import okio.Path
import okio.Path.Companion.toOkioPath
import kotlinx.io.files.Path
import java.io.File
import java.io.PrintWriter
import java.util.regex.Pattern
Expand All @@ -25,17 +24,17 @@ sealed class FileLoggingSetup : IFileLoggingSetup {
getFilePathsInFolder().filter { Pattern.matches(pattern, it.name) }

override fun getLatestLogFilePath() =
getAllExistingLogFilePaths().maxByOrNull { it.toFile().lastModified() }
getAllExistingLogFilePaths().maxByOrNull { File(it.toString()).lastModified() }

override suspend fun clearLogFiles() {
withContext(Dispatchers.IO) {
val newestFile = getLatestLogFilePath()
val filesToDelete = getAllExistingLogFilePaths().filter { it != newestFile }
filesToDelete.forEach {
it.toFile().delete()
File(it.toString()).delete()
}
newestFile?.let {
val writer = PrintWriter(it.toFile())
val writer = PrintWriter(File(it.toString()))
writer.print("")
writer.close()
}
Expand Down Expand Up @@ -72,7 +71,7 @@ sealed class FileLoggingSetup : IFileLoggingSetup {
/*
* we know the file name of the newest file before hand, no need to check all files in the folder
*/
override fun getLatestLogFilePath() = File(baseFilePath).toOkioPath()
override fun getLatestLogFilePath() = Path(baseFilePath)
}

@Parcelize
Expand Down Expand Up @@ -119,6 +118,6 @@ sealed class FileLoggingSetup : IFileLoggingSetup {
if (!folder.exists()) {
return emptyList()
}
return folder.listFiles()?.filter { it.isFile }?.map { it.toOkioPath() } ?: emptyList()
return folder.listFiles()?.filter { it.isFile }?.map { Path(it.absolutePath) } ?: emptyList()
}
}

0 comments on commit 34b7950

Please sign in to comment.