-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Compose Viewer shows file sizes now
* Lumberjack Setups do use Companion.create functions instead of overloaded constructors * added a BaseFileLoggerSetup * added a new file size based setup to the lumberjack file logger setups
- Loading branch information
Showing
13 changed files
with
237 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import com.michaelflisar.lumberjack.demo.DemoLogging | |
import com.michaelflisar.lumberjack.extensions.composeviewer.LumberjackDialog | ||
import com.michaelflisar.lumberjack.extensions.feedback.sendFeedback | ||
import com.michaelflisar.lumberjack.extensions.viewer.showLog | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class MainActivity : DemoBaseActivity() { | ||
|
@@ -50,9 +51,8 @@ class MainActivity : DemoBaseActivity() { | |
var mail by rememberSaveable { | ||
mutableStateOf("") | ||
} | ||
val showComposeLogView = rememberSaveable { | ||
mutableStateOf(false) | ||
} | ||
val showComposeLogView = rememberSaveable { mutableStateOf(false) } | ||
val showComposeLogView2 = rememberSaveable { mutableStateOf(false) } | ||
|
||
Column( | ||
modifier = modifier | ||
|
@@ -85,6 +85,15 @@ class MainActivity : DemoBaseActivity() { | |
}) { | ||
Text("Log Viewer (Compose)") | ||
} | ||
if (DemoLogging.FILE_LOGGING_SETUP2 != null) { | ||
OutlinedButton( | ||
modifier = Modifier.fillMaxWidth(), | ||
onClick = { | ||
showComposeLogView2.value = true | ||
}) { | ||
Text("Log Viewer (Compose) - Setup2") | ||
} | ||
} | ||
} | ||
DemoCollapsibleRegion( | ||
title = "Actions", | ||
|
@@ -131,6 +140,17 @@ class MainActivity : DemoBaseActivity() { | |
}) { | ||
Text("Log something") | ||
} | ||
OutlinedButton( | ||
modifier = Modifier.fillMaxWidth(), | ||
onClick = { | ||
scope.launch(Dispatchers.IO) { | ||
(1..100).forEach { | ||
L.d { "Logging a lot $it..." } | ||
} | ||
} | ||
}) { | ||
Text("Log a lot") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -141,5 +161,15 @@ class MainActivity : DemoBaseActivity() { | |
darkTheme = theme.isDark(), | ||
//mail = "[email protected]" | ||
) | ||
|
||
if (DemoLogging.FILE_LOGGING_SETUP2 != null) { | ||
LumberjackDialog( | ||
visible = showComposeLogView2, | ||
title = "Logs", | ||
setup = DemoLogging.FILE_LOGGING_SETUP2!!, | ||
darkTheme = theme.isDark(), | ||
//mail = "[email protected]" | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
[versions] | ||
core = "1.12.0" | ||
lifecycle = "2.6.2" | ||
constraintlayout = "2.1.4" | ||
lifecycle = "2.7.0" | ||
recyclerview = "1.3.2" | ||
|
||
|
||
[libraries] | ||
core = { module = "androidx.core:core-ktx", version.ref = "core" } | ||
lifecycle = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" } | ||
constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" } | ||
recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
[versions] | ||
composeBom = "2023.10.01" | ||
compiler = "1.5.3" | ||
composeBom = "2024.03.00" | ||
compiler = "1.5.10" | ||
|
||
lifecycle = "2.6.2" | ||
activity = "1.8.0" | ||
activity = "1.8.2" | ||
accompanist = "0.32.0" | ||
|
||
[libraries] | ||
bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } | ||
animation = { group = "androidx.compose.animation", name = "animation" } | ||
foundation = { group = "androidx.compose.foundation", name = "foundation" } | ||
material = { group = "androidx.compose.material", name = "material" } | ||
runtime = { group = "androidx.compose.runtime", name = "runtime" } | ||
ui = { group = "androidx.compose.ui", name = "ui" } | ||
ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } | ||
ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } | ||
material-extendedicons = { group = "androidx.compose.material", name = "material-icons-extended" } | ||
material3 = { group = "androidx.compose.material3", name = "material3" } | ||
bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } | ||
icons-material-extendedicons = { group = "androidx.compose.material", name = "material-icons-extended" } | ||
material3 = { group = "androidx.compose.material3", name = "material3" } | ||
|
||
lifecycle = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle" } | ||
activity = { module = "androidx.activity:activity-compose", version.ref = "activity" } | ||
activity = { module = "androidx.activity:activity-compose", version.ref = "activity" } | ||
|
||
systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" } | ||
drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" } | ||
drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...rjack/file/src/main/java/com/michaelflisar/lumberjack/loggers/file/BaseFileLoggerSetup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.michaelflisar.lumberjack.loggers.file | ||
|
||
import com.michaelflisar.lumberjack.implementation.LumberjackLogger | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.parcelize.IgnoredOnParcel | ||
import java.io.File | ||
|
||
abstract class BaseFileLoggerSetup : FileLoggerSetup() { | ||
|
||
abstract val folder: File | ||
abstract val fileBaseName: String | ||
abstract val fileExtension: String | ||
abstract var lastFileKey: String | ||
abstract var lastFileKeyChanged: Boolean | ||
|
||
@IgnoredOnParcel | ||
override val fileConverter = FileConverter | ||
|
||
override fun filePath(data: FileLogger.Event.Data): String { | ||
val lastPath = "${folder.path}/${fileBaseName}_${lastFileKey}.$fileExtension" | ||
val key = getFileKey(data, lastPath) | ||
val path = "${folder.path}/${fileBaseName}_${key}.$fileExtension" | ||
if (key != lastFileKey) { | ||
lastFileKey = key | ||
lastFileKeyChanged = true | ||
} | ||
return path | ||
} | ||
|
||
abstract fun getFileKey(data: FileLogger.Event.Data, lastPath: String): String | ||
abstract fun filterLogFilesToDelete(files: List<File>): List<File> | ||
|
||
protected fun getKeyFromFile(file: File) : String { | ||
return file.nameWithoutExtension.replace(fileBaseName, "").substring(1) | ||
} | ||
|
||
override fun onLogged(scope: CoroutineScope) { | ||
if (lastFileKeyChanged) { | ||
lastFileKeyChanged = false | ||
scope.launch { | ||
clearLogFiles(false) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun clearLogFiles() { | ||
clearLogFiles(true) | ||
} | ||
|
||
override fun getAllExistingLogFiles(): List<File> { | ||
return folder.listFiles()?.filter { | ||
it.name.startsWith(fileBaseName) | ||
}?.sortedByDescending { it.name } ?: emptyList() | ||
} | ||
|
||
override fun getLatestLogFiles(): File? { | ||
return getAllExistingLogFiles().firstOrNull() | ||
} | ||
|
||
private suspend fun clearLogFiles(all: Boolean) { | ||
withContext(Dispatchers.IO) { | ||
val files = getAllExistingLogFiles() | ||
val filesToDelete = if (all) files else filterLogFilesToDelete(files) | ||
if (filesToDelete.isNotEmpty()) { | ||
LumberjackLogger.loggers() | ||
.filterIsInstance<FileLogger>() | ||
.filter { | ||
it.setup == this@BaseFileLoggerSetup | ||
} | ||
.forEach { | ||
it.onLogFilesWillBeDeleted(filesToDelete) | ||
} | ||
filesToDelete.forEach { | ||
it.delete() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.