Skip to content

Commit

Permalink
IFileLoggingSetup: getLatestLogFiles renamed to getLatestLogFile
Browse files Browse the repository at this point in the history
added FileSizeUtil.kt
  • Loading branch information
MFlisarWork committed Oct 15, 2024
1 parent 5e97f50 commit 8cb82c3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fun Level.getColor(darkTheme: Boolean = isSystemInDarkTheme()): Color {
color?.let { Color(it) } ?:
Color.Unspecified
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.michaelflisar.lumberjack.extensions.composeviewer

import java.text.DecimalFormat
import kotlin.math.log10
import kotlin.math.pow

object FileSizeUtil {

fun humanReadableBytes(bytes: Long): String {
val units = arrayOf("B", "kB", "MB", "GB", "TB")
val digitGroups = if (bytes == 0L) 0 else (log10(bytes.toDouble()) / log10(1024.0)).toInt()
return DecimalFormat("#,##0.#").format(bytes / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,8 @@ private fun Info(file: Path?, filteredCount: Int, totalCount: Int) {
Row(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
) {
val size =
(file?.let { FileSystem.SYSTEM.metadataOrNull(it) }?.size?.toDouble() ?: 0.0) / 1000.0

val info = ((size * 100).toInt() / 100.0).toString() + "kB"
//val info = "%.2fkB".format((file?.length()?.toDouble() ?: 0.0) / 1000.0)

val size = file?.let { FileSystem.SYSTEM.metadataOrNull(it) }?.size ?: 0L
val info = FileSizeUtil.humanReadableBytes(size)
Text(
modifier = Modifier.weight(1f),
maxLines = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ interface IFileLoggingSetup : Parcelable {
val fileConverter: IFileConverter

fun getAllExistingLogFiles(): List<File>
fun getLatestLogFiles(): File?
fun getLatestLogFile(): File?
suspend fun clearLogFiles()


}

0 comments on commit 8cb82c3

Please sign in to comment.