Skip to content

Commit

Permalink
Add no-op implementation of logger.
Browse files Browse the repository at this point in the history
Fix typo in package naming.
  • Loading branch information
Bojan committed Apr 25, 2021
1 parent 2c3a2ea commit 7280f7d
Show file tree
Hide file tree
Showing 29 changed files with 159 additions and 45 deletions.
13 changes: 13 additions & 0 deletions dbinspector-no-op/proguard-rules.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
-keep public class com.infinum.dbinspector.DbInspector {
public protected *;
}
-keep public class com.infinum.dbinspector.data.models.memory.logger.Level {
public protected *;
}
-keep public class com.infinum.dbinspector.data.sources.memory.logger.Logger {
public protected *;
}
-keep public class com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger {
public protected *;
}
-keep public class com.infinum.dbinspector.data.sources.memory.logger.AndroidLogger {
public protected *;
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.infinum.dbinspector

import com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.sources.memory.logger.Logger

@Suppress("UnusedPrivateMember")
public object DbInspector {

@JvmStatic
public fun show(): Unit = Unit
public fun show(logger: Logger = EmptyLogger()): Unit = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.infinum.dbinspector.data.models.memory.logger

public enum class Level {
DEBUG,
INFO,
ERROR,
NONE
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.logger
package com.infinum.dbinspector.data.sources.memory.logger

import android.util.Log
import com.infinum.dbinspector.data.models.memory.logger.Level
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.logger
package com.infinum.dbinspector.data.sources.memory.logger

import com.infinum.dbinspector.data.models.memory.logger.Level

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.logger
package com.infinum.dbinspector.data.sources.memory.logger

import com.infinum.dbinspector.data.models.memory.logger.Level

Expand All @@ -10,6 +10,7 @@ public abstract class Logger(
internal const val DEFAULT_LOG_TAG = "[DbInspector]"
}

@Suppress("MemberVisibilityCanBePrivate")
public var tag: String? = null

public abstract fun log(level: Level, message: String)
Expand Down
14 changes: 14 additions & 0 deletions dbinspector/proguard-rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
-keep public class com.infinum.dbinspector.DbInspector {
public protected *;
}
-keep public class com.infinum.dbinspector.data.models.memory.logger.Level {
public protected *;
}

-keep public class com.infinum.dbinspector.data.sources.memory.logger.Logger {
public protected *;
}

-keep public class com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger {
public protected *;
}
-keep public class com.infinum.dbinspector.data.sources.memory.logger.AndroidLogger {
public protected *;
}
-keep class androidx.datastore.*.* {*;}
-keepclassmembers class * extends androidx.datastore.* {
<fields>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.infinum.dbinspector

import android.content.Intent
import com.infinum.dbinspector.data.source.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.ui.Presentation
import com.infinum.dbinspector.ui.databases.DatabasesActivity

Expand Down
22 changes: 11 additions & 11 deletions dbinspector/src/main/kotlin/com/infinum/dbinspector/data/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import com.infinum.dbinspector.data.Data.Constants.Name.PROTO_FILENAME_HISTORY
import com.infinum.dbinspector.data.Data.Constants.Name.PROTO_FILENAME_SETTINGS
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import com.infinum.dbinspector.data.models.local.proto.output.SettingsEntity
import com.infinum.dbinspector.data.source.local.cursor.PragmaSource
import com.infinum.dbinspector.data.source.local.cursor.RawQuerySource
import com.infinum.dbinspector.data.source.local.cursor.SchemaSource
import com.infinum.dbinspector.data.source.local.proto.history.HistoryDataStore
import com.infinum.dbinspector.data.source.local.proto.history.HistorySerializer
import com.infinum.dbinspector.data.source.local.proto.settings.SettingsDataStore
import com.infinum.dbinspector.data.source.local.proto.settings.SettingsSerializer
import com.infinum.dbinspector.data.source.memory.connection.AndroidConnectionSource
import com.infinum.dbinspector.data.source.memory.pagination.CursorPaginator
import com.infinum.dbinspector.data.source.memory.pagination.Paginator
import com.infinum.dbinspector.data.source.raw.AndroidDatabasesSource
import com.infinum.dbinspector.data.sources.local.cursor.PragmaSource
import com.infinum.dbinspector.data.sources.local.cursor.RawQuerySource
import com.infinum.dbinspector.data.sources.local.cursor.SchemaSource
import com.infinum.dbinspector.data.sources.local.proto.history.HistoryDataStore
import com.infinum.dbinspector.data.sources.local.proto.history.HistorySerializer
import com.infinum.dbinspector.data.sources.local.proto.settings.SettingsDataStore
import com.infinum.dbinspector.data.sources.local.proto.settings.SettingsSerializer
import com.infinum.dbinspector.data.sources.memory.connection.AndroidConnectionSource
import com.infinum.dbinspector.data.sources.memory.pagination.CursorPaginator
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.raw.AndroidDatabasesSource
import com.infinum.dbinspector.extensions.dataStoreFile
import org.koin.core.module.Module
import org.koin.core.qualifier.StringQualifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.cursor
package com.infinum.dbinspector.data.sources.local.cursor

import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.cursor.exceptions.CursorException
Expand All @@ -8,9 +8,9 @@ import com.infinum.dbinspector.data.models.local.cursor.output.Field
import com.infinum.dbinspector.data.models.local.cursor.output.FieldType
import com.infinum.dbinspector.data.models.local.cursor.output.QueryResult
import com.infinum.dbinspector.data.models.local.cursor.output.Row
import com.infinum.dbinspector.data.source.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.source.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.suspendCancellableCoroutine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.cursor
package com.infinum.dbinspector.data.sources.local.cursor

import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.cursor.exceptions.CursorException
Expand All @@ -8,9 +8,9 @@ import com.infinum.dbinspector.data.models.local.cursor.output.Field
import com.infinum.dbinspector.data.models.local.cursor.output.FieldType
import com.infinum.dbinspector.data.models.local.cursor.output.QueryResult
import com.infinum.dbinspector.data.models.local.cursor.output.Row
import com.infinum.dbinspector.data.source.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.source.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.suspendCancellableCoroutine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.infinum.dbinspector.data.source.local.cursor
package com.infinum.dbinspector.data.sources.local.cursor

import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.cursor.input.Query
import com.infinum.dbinspector.data.models.local.cursor.output.QueryResult
import com.infinum.dbinspector.data.source.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.source.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.local.cursor.shared.CursorSource
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import kotlinx.coroutines.suspendCancellableCoroutine

@Suppress("LongParameterList")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.cursor.shared
package com.infinum.dbinspector.data.sources.local.cursor.shared

import android.database.Cursor
import androidx.core.database.getBlobOrNull
Expand All @@ -13,8 +13,8 @@ import com.infinum.dbinspector.data.models.local.cursor.output.FieldType
import com.infinum.dbinspector.data.models.local.cursor.output.QueryResult
import com.infinum.dbinspector.data.models.local.cursor.output.Row
import com.infinum.dbinspector.data.models.local.proto.output.SettingsEntity
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.source.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import com.infinum.dbinspector.extensions.lowercase
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.proto.history
package com.infinum.dbinspector.data.sources.local.proto.history

import androidx.datastore.core.DataStore
import com.infinum.dbinspector.data.Sources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.proto.history
package com.infinum.dbinspector.data.sources.local.proto.history

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.proto.settings
package com.infinum.dbinspector.data.sources.local.proto.settings

import androidx.datastore.core.DataStore
import com.infinum.dbinspector.data.Sources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.local.proto.settings
package com.infinum.dbinspector.data.sources.local.proto.settings

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.connection
package com.infinum.dbinspector.data.sources.memory.connection

import android.database.sqlite.SQLiteDatabase
import com.infinum.dbinspector.data.Sources
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.infinum.dbinspector.data.sources.memory.logger

import android.util.Log
import com.infinum.dbinspector.data.models.memory.logger.Level

public class AndroidLogger(
level: Level = Level.INFO
) : Logger(level) {

override fun log(level: Level, message: String) {
if (this.level <= level) {
logOnLevel(message, level)
}
}

private fun logOnLevel(message: String, level: Level) {
when (level) {
Level.DEBUG -> Log.d(tag(), message)
Level.INFO -> Log.i(tag(), message)
Level.ERROR -> Log.e(tag(), message)
else -> Log.e(tag(), message)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.infinum.dbinspector.data.sources.memory.logger

import com.infinum.dbinspector.data.models.memory.logger.Level

internal class EmptyLogger : Logger(Level.NONE) {

override fun log(level: Level, message: String) = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.infinum.dbinspector.data.sources.memory.logger

import com.infinum.dbinspector.data.models.memory.logger.Level

public abstract class Logger(
public var level: Level = Level.INFO
) {

public companion object {
internal const val DEFAULT_LOG_TAG = "[DbInspector]"
}

@Suppress("MemberVisibilityCanBePrivate")
public var tag: String? = null

public abstract fun log(level: Level, message: String)

public fun debug(message: String) {
doLog(Level.DEBUG, message)
}

public fun info(message: String) {
doLog(Level.INFO, message)
}

public fun error(message: String) {
doLog(Level.ERROR, message)
}

protected fun tag(): String = tag ?: DEFAULT_LOG_TAG

private fun canLog(level: Level): Boolean = this.level <= level

private fun doLog(level: Level, message: String) {
if (canLog(level)) {
log(level, message)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.pagination
package com.infinum.dbinspector.data.sources.memory.pagination

import com.infinum.dbinspector.extensions.orZero
import kotlin.math.ceil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.memory.pagination
package com.infinum.dbinspector.data.sources.memory.pagination

internal interface Paginator {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.infinum.dbinspector.data.source.raw
package com.infinum.dbinspector.data.sources.raw

import com.infinum.dbinspector.R
import com.infinum.dbinspector.data.Sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.infinum.dbinspector.di

import android.content.Context
import com.infinum.dbinspector.BuildConfig
import com.infinum.dbinspector.data.source.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.ui.Presentation
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.infinum.dbinspector.ui

import android.annotation.SuppressLint
import android.content.Context
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.di.LibraryKoin
import com.infinum.dbinspector.domain.Domain
import com.infinum.dbinspector.ui.content.table.TableViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.infinum.dbinspector.ui.shared.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.infinum.dbinspector.data.source.memory.logger.Logger
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.di.LibraryKoinComponent
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
debug {
debuggable true
minifyEnabled false
applicationIdSuffix ".debug"
}
release {
debuggable false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.infinum.dbinspector.sample
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.infinum.dbinspector.DbInspector
import com.infinum.dbinspector.data.source.memory.logger.AndroidLogger
import com.infinum.dbinspector.data.sources.memory.logger.AndroidLogger
import com.infinum.dbinspector.sample.databinding.ActivityMainBinding
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand All @@ -14,6 +14,8 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

supportActionBar?.title = "${supportActionBar?.title?.toString().orEmpty()} (${BuildConfig.BUILD_TYPE})"

ActivityMainBinding.inflate(layoutInflater)
.also { setContentView(it.root) }
.also {
Expand Down

0 comments on commit 7280f7d

Please sign in to comment.