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..d442faf 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) @@ -35,6 +41,9 @@ internal fun getLogs(): LiveData> = internal fun getCategories(): List = appLoggerBLInstance?.categories ?: emptyList() +internal fun arePersistedLogsEnabled() : Boolean = + appLoggerBLInstance?.arePersistedLogsEnabled() ?: false + internal fun getPersistedLogs(callback: TaskCallback) { appLoggerBLInstance?.getPersistedLogs(callback) } 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..0befa7b 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,19 +47,22 @@ 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> = logsData + open fun arePersistedLogsEnabled(): Boolean = + fileLogger != null + 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) { diff --git a/library/src/enabled/java/com/telefonica/androidlogger/ui/AppLoggerActivity.kt b/library/src/enabled/java/com/telefonica/androidlogger/ui/AppLoggerActivity.kt index e639e21..daa718d 100644 --- a/library/src/enabled/java/com/telefonica/androidlogger/ui/AppLoggerActivity.kt +++ b/library/src/enabled/java/com/telefonica/androidlogger/ui/AppLoggerActivity.kt @@ -32,6 +32,7 @@ import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup import com.telefonica.androidlogger.R import com.telefonica.androidlogger.domain.LogCategory +import com.telefonica.androidlogger.domain.arePersistedLogsEnabled import com.telefonica.androidlogger.io.executor.TaskCallback import com.telefonica.androidlogger.ui.adapter.LogListAdapter import com.telefonica.androidlogger.ui.viewmodel.AppLoggerViewModel @@ -79,7 +80,9 @@ class AppLoggerActivity : AppCompatActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_app_logger, menu) - + if (!arePersistedLogsEnabled()) { + menu.removeItem(R.id.action_share_all) + } searchView = (menu.findItem(R.id.action_search).actionView as SearchView).apply { val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager setSearchableInfo(searchManager.getSearchableInfo(componentName))