-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohsen <[email protected]>
- Loading branch information
Showing
4 changed files
with
42 additions
and
14 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
28 changes: 28 additions & 0 deletions
28
app/src/main/kotlin/com/mohsenoid/rickandmorty/startup/TimberInitializer.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,28 @@ | ||
package com.mohsenoid.rickandmorty.startup | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
import com.mohsenoid.rickandmorty.BuildConfig | ||
import timber.log.Timber | ||
|
||
class TimberInitializer : Initializer<Unit> { | ||
|
||
private val isDebug: Boolean = BuildConfig.DEBUG | ||
|
||
override fun create(context: Context) { | ||
if (isDebug) setupTimber() | ||
} | ||
|
||
private fun setupTimber() { | ||
Timber.plant( | ||
object : Timber.DebugTree() { | ||
override fun createStackElementTag(element: StackTraceElement): String { | ||
// adding file name and line number link to logs | ||
return "${super.createStackElementTag(element)}(${element.fileName}:${element.lineNumber})" | ||
} | ||
}, | ||
) | ||
} | ||
|
||
override fun dependencies(): MutableList<Class<out Initializer<*>>> = mutableListOf() | ||
} |