util: use timber for logging
This will make testing app components a lot easier since it removes the logging dependency used in most shared objects.
This commit is contained in:
parent
fcffb56021
commit
9a67a0d539
7 changed files with 21 additions and 22 deletions
|
@ -142,13 +142,15 @@ dependencies {
|
||||||
implementation "com.google.dagger:hilt-android:$hilt_version"
|
implementation "com.google.dagger:hilt-android:$hilt_version"
|
||||||
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
|
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
implementation 'com.jakewharton.timber:timber:5.0.1'
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
||||||
testImplementation "junit:junit:4.13.2"
|
testImplementation "junit:junit:4.13.2"
|
||||||
testImplementation "io.mockk:mockk:1.13.7"
|
testImplementation "io.mockk:mockk:1.13.7"
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spotless {
|
spotless {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.oxycblt.auxio.home.HomeSettings
|
||||||
import org.oxycblt.auxio.image.ImageSettings
|
import org.oxycblt.auxio.image.ImageSettings
|
||||||
import org.oxycblt.auxio.playback.PlaybackSettings
|
import org.oxycblt.auxio.playback.PlaybackSettings
|
||||||
import org.oxycblt.auxio.ui.UISettings
|
import org.oxycblt.auxio.ui.UISettings
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple, rational music player for android.
|
* A simple, rational music player for android.
|
||||||
|
@ -44,6 +45,10 @@ class Auxio : Application() {
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Timber.plant(Timber.DebugTree())
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate any settings that may have changed in an app update.
|
// Migrate any settings that may have changed in an app update.
|
||||||
imageSettings.migrate()
|
imageSettings.migrate()
|
||||||
playbackSettings.migrate()
|
playbackSettings.migrate()
|
||||||
|
|
|
@ -51,7 +51,7 @@ constructor(
|
||||||
// Apply the new configuration possibly set in flipTo. This should occur even if
|
// Apply the new configuration possibly set in flipTo. This should occur even if
|
||||||
// a flip was canceled by a hide.
|
// a flip was canceled by a hide.
|
||||||
pendingConfig?.run {
|
pendingConfig?.run {
|
||||||
this@FlipFloatingActionButton.logD("Applying pending configuration")
|
logD("Applying pending configuration")
|
||||||
setImageResource(iconRes)
|
setImageResource(iconRes)
|
||||||
contentDescription = context.getString(contentDescriptionRes)
|
contentDescription = context.getString(contentDescriptionRes)
|
||||||
setOnClickListener(clickListener)
|
setOnClickListener(clickListener)
|
||||||
|
|
|
@ -24,6 +24,9 @@ import org.oxycblt.auxio.util.positiveOrNull
|
||||||
|
|
||||||
// TODO: Remove the escaping checks, it's too expensive to do this for every single tag.
|
// TODO: Remove the escaping checks, it's too expensive to do this for every single tag.
|
||||||
|
|
||||||
|
// TODO: I want to eventually be able to move a lot of this into TagWorker once I no longer have
|
||||||
|
// to deal with the cross-module dependencies of MediaStoreExtractor.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a [String] by the given selector, automatically handling escaped characters that satisfy
|
* Split a [String] by the given selector, automatically handling escaped characters that satisfy
|
||||||
* the selector.
|
* the selector.
|
||||||
|
|
|
@ -338,8 +338,7 @@ constructor(
|
||||||
song,
|
song,
|
||||||
object : BitmapProvider.Target {
|
object : BitmapProvider.Target {
|
||||||
override fun onCompleted(bitmap: Bitmap?) {
|
override fun onCompleted(bitmap: Bitmap?) {
|
||||||
this@MediaSessionComponent.logD(
|
logD("Bitmap loaded, applying media session and posting notification")
|
||||||
"Bitmap loaded, applying media session and posting notification")
|
|
||||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
|
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
|
||||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
|
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
|
||||||
val metadata = builder.build()
|
val metadata = builder.build()
|
||||||
|
|
|
@ -119,7 +119,7 @@ class SearchFragment : ListFragment<Music, FragmentSearchBinding>() {
|
||||||
|
|
||||||
if (!launchedKeyboard) {
|
if (!launchedKeyboard) {
|
||||||
// Auto-open the keyboard when this view is shown
|
// Auto-open the keyboard when this view is shown
|
||||||
this@SearchFragment.logD("Keyboard is not shown yet")
|
logD("Keyboard is not shown yet")
|
||||||
showKeyboard(this)
|
showKeyboard(this)
|
||||||
launchedKeyboard = true
|
launchedKeyboard = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,27 +18,24 @@
|
||||||
|
|
||||||
package org.oxycblt.auxio.util
|
package org.oxycblt.auxio.util
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import org.oxycblt.auxio.BuildConfig
|
import org.oxycblt.auxio.BuildConfig
|
||||||
|
import timber.log.Timber
|
||||||
// Shortcut functions for logging.
|
|
||||||
// Yes, I know timber exists but this does what I need.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log an object to the debug channel. Automatically handles tags.
|
* Log an object to the debug channel. Automatically handles tags.
|
||||||
*
|
*
|
||||||
* @param obj The object to log.
|
* @param obj The object to log.
|
||||||
*/
|
*/
|
||||||
fun Any.logD(obj: Any?) = logD("$obj")
|
fun logD(obj: Any?) = logD("$obj")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a string message to the debug channel. Automatically handles tags.
|
* Log a string message to the debug channel. Automatically handles tags.
|
||||||
*
|
*
|
||||||
* @param msg The message to log.
|
* @param msg The message to log.
|
||||||
*/
|
*/
|
||||||
fun Any.logD(msg: String) {
|
fun logD(msg: String) {
|
||||||
if (BuildConfig.DEBUG && !copyleftNotice()) {
|
if (BuildConfig.DEBUG && !copyleftNotice()) {
|
||||||
Log.d(autoTag, msg)
|
Timber.d(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,21 +44,14 @@ fun Any.logD(msg: String) {
|
||||||
*
|
*
|
||||||
* @param msg The message to log.
|
* @param msg The message to log.
|
||||||
*/
|
*/
|
||||||
fun Any.logW(msg: String) = Log.w(autoTag, msg)
|
fun logW(msg: String) = Timber.w(msg)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a string message to the error channel. Automatically handles tags.
|
* Log a string message to the error channel. Automatically handles tags.
|
||||||
*
|
*
|
||||||
* @param msg The message to log.
|
* @param msg The message to log.
|
||||||
*/
|
*/
|
||||||
fun Any.logE(msg: String) = Log.e(autoTag, msg)
|
fun logE(msg: String) = Timber.e(msg)
|
||||||
|
|
||||||
/**
|
|
||||||
* The LogCat-suitable tag for this string. Consists of the object's name, or "Anonymous Object" if
|
|
||||||
* the object does not exist.
|
|
||||||
*/
|
|
||||||
private val Any.autoTag: String
|
|
||||||
get() = "Auxio.${this::class.simpleName ?: "Anonymous Object"}"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Please don't plagiarize Auxio! You are free to remove this as long as you continue to keep your
|
* Please don't plagiarize Auxio! You are free to remove this as long as you continue to keep your
|
||||||
|
@ -71,7 +61,7 @@ private val Any.autoTag: String
|
||||||
private fun copyleftNotice(): Boolean {
|
private fun copyleftNotice(): Boolean {
|
||||||
if (BuildConfig.APPLICATION_ID != "org.oxycblt.auxio" &&
|
if (BuildConfig.APPLICATION_ID != "org.oxycblt.auxio" &&
|
||||||
BuildConfig.APPLICATION_ID != "org.oxycblt.auxio.debug") {
|
BuildConfig.APPLICATION_ID != "org.oxycblt.auxio.debug") {
|
||||||
Log.d(
|
Timber.d(
|
||||||
"Auxio Project",
|
"Auxio Project",
|
||||||
"Friendly reminder: Auxio is licensed under the " +
|
"Friendly reminder: Auxio is licensed under the " +
|
||||||
"GPLv3 and all derivative apps must be made open source!")
|
"GPLv3 and all derivative apps must be made open source!")
|
||||||
|
|
Loading…
Reference in a new issue