Skip to content

Commit

Permalink
Allow disable File Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelga committed Dec 12, 2024
1 parent 24ee17b commit 49457ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import java.util.concurrent.Executors
internal var appLoggerBLInstance: AppLoggerBL? = null

@JvmOverloads
fun initAppLogger(context: Context, logCategories: List<LogCategory> = emptyList()) {
fun initAppLogger(
context: Context,
logCategories: List<LogCategory> = emptyList(),
logToDisk: Boolean = true
) {
appLoggerBLInstance = AppLoggerBL(
fileLogger = AppFileLogger(
appContext = context,
executor = Executor(Executors.newSingleThreadExecutor())),
fileLogger = if (logToDisk) {
AppFileLogger(context,Executor(Executors.newSingleThreadExecutor()))
} else {
null
},
consoleLogger = AppConsoleLogger()
).apply {
init(context, logCategories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.*
import kotlin.collections.ArrayList

internal open class AppLoggerBL(
private val fileLogger: AppFileLogger,
private val fileLogger: AppFileLogger?,
private val consoleLogger: AppConsoleLogger
) {
private val logs: LinkedList<LogEntry> = LinkedList()
Expand All @@ -32,7 +32,7 @@ internal open class AppLoggerBL(
}
}.groupBy({ it.first }, { it.second })
logsData.value = emptyList()
fileLogger.init()
fileLogger?.init()
}

open fun log(@LogPriority priority: Int, tag: String, message: String, throwable: Throwable?) {
Expand All @@ -47,19 +47,19 @@ internal open class AppLoggerBL(
message = messageToLog
)
)
fileLogger.log(priority, tag, messageToLog)
fileLogger?.log(priority, tag, messageToLog)
consoleLogger.log(priority, tag, messageToLog)
}

open fun getLogs(): LiveData<List<LogEntry>> =
logsData

open fun getPersistedLogs(callback: TaskCallback<Uri>) {
fileLogger.getReport(callback)
fileLogger?.getReport(callback)
}

fun storeVisibleLogs(visibleLogs: String, callback: TaskCallback<Uri>) {
fileLogger.storeVisibleLogs(visibleLogs, callback)
fileLogger?.storeVisibleLogs(visibleLogs, callback)
}

private fun addLog(logEntry: LogEntry) {
Expand Down

0 comments on commit 49457ba

Please sign in to comment.