Skip to content

Commit

Permalink
bugfix: lumberjack file logger daily setup did not delete the correct…
Browse files Browse the repository at this point in the history
… files in the last version
  • Loading branch information
MFlisar committed Apr 5, 2024
1 parent 74f1f35 commit a0ac0ec
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import kotlin.math.min

sealed class FileLoggerSetup : IFileLoggingSetup {

companion object {
private const val DEFAULT_LOG_FILE_FOLDER = "lumberjack"
private const val DEFAULT_SIZE_LIMIT_5MB = 5 * 1000 * 1000 // 5MB
}

abstract fun filePath(data: FileLogger.Event.Data): String
abstract fun onLogged(scope: CoroutineScope)

Expand All @@ -33,7 +38,7 @@ sealed class FileLoggerSetup : IFileLoggingSetup {
fileExtension: String = "log",
filesToKeep: Int = 1
) = Daily(
File(context.filesDir, "lumberjack"),
File(context.filesDir, DEFAULT_LOG_FILE_FOLDER),
fileBaseName,
fileExtension,
filesToKeep
Expand Down Expand Up @@ -61,7 +66,7 @@ sealed class FileLoggerSetup : IFileLoggingSetup {
}

override fun filterLogFilesToDelete(files: List<File>): List<File> {
return files.dropLast((files.size - filesToKeep).coerceAtLeast(0))
return files.drop(filesToKeep)
}
}

Expand All @@ -78,16 +83,14 @@ sealed class FileLoggerSetup : IFileLoggingSetup {

companion object {

const val DEFAULT_SIZE = 5 * 1000 * 1000 // 5MB

fun create(
context: Context,
fileBaseName: String = "log",
fileExtension: String = "log",
filesToKeep: Int = 1,
maxFileSizeInBytes: Int = DEFAULT_SIZE
maxFileSizeInBytes: Int = DEFAULT_SIZE_LIMIT_5MB
) = FileSize(
File(context.filesDir, "lumberjack"),
File(context.filesDir, DEFAULT_LOG_FILE_FOLDER),
fileBaseName,
fileExtension,
filesToKeep,
Expand All @@ -99,7 +102,7 @@ sealed class FileLoggerSetup : IFileLoggingSetup {
fileBaseName: String = "log",
fileExtension: String = "log",
filesToKeep: Int = 1,
maxFileSizeInBytes: Int = DEFAULT_SIZE
maxFileSizeInBytes: Int = DEFAULT_SIZE_LIMIT_5MB
) = FileSize(folder, fileBaseName, fileExtension, filesToKeep, maxFileSizeInBytes)
}

Expand Down

0 comments on commit a0ac0ec

Please sign in to comment.