diff --git a/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLogger.kt b/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLogger.kt index 88619c6..347563c 100644 --- a/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLogger.kt +++ b/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLogger.kt @@ -13,11 +13,17 @@ import java.util.concurrent.Executors internal var appLoggerBLInstance: AppLoggerBL? = null @JvmOverloads -fun initAppLogger(context: Context, logCategories: List = emptyList()) { +fun initAppLogger( + context: Context, + logCategories: List = 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) diff --git a/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLoggerBL.kt b/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLoggerBL.kt index 24d2bf1..563f3ea 100644 --- a/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLoggerBL.kt +++ b/library/src/enabled/java/com/telefonica/androidlogger/domain/AppLoggerBL.kt @@ -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 = LinkedList() @@ -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?) { @@ -47,7 +47,7 @@ internal open class AppLoggerBL( message = messageToLog ) ) - fileLogger.log(priority, tag, messageToLog) + fileLogger?.log(priority, tag, messageToLog) consoleLogger.log(priority, tag, messageToLog) } @@ -55,11 +55,11 @@ internal open class AppLoggerBL( logsData open fun getPersistedLogs(callback: TaskCallback) { - fileLogger.getReport(callback) + fileLogger?.getReport(callback) } fun storeVisibleLogs(visibleLogs: String, callback: TaskCallback) { - fileLogger.storeVisibleLogs(visibleLogs, callback) + fileLogger?.storeVisibleLogs(visibleLogs, callback) } private fun addLog(logEntry: LogEntry) {