aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
blob: 86731357afcf1a2cf7363b2e52321e9e5f263ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.pitchedapps.frost.utils

import android.util.Log
import ca.allanwang.kau.logging.TimberLogger
import com.crashlytics.android.Crashlytics
import timber.log.Timber


/**
 * Created by Allan Wang on 2017-05-28.
 *
 * Logging for frost
 *
 * To ensure privacy, the following rules are set:
 *
 * Debug and Error logs must not reveal person info
 * Person info logs can be marked as info or verbose
 */
object L : TimberLogger("Frost") {

    /**
     * Helper function to separate private info
     */
    fun d(tag: String, personal: String?) {
        L.d(tag)
        L.i("-\t$personal")
    }
}

internal class CrashReportingTree : Timber.Tree() {
    override fun log(priority: Int, tag: String?, message: String?, t: Throwable?) {
        when (priority) {
            Log.VERBOSE, Log.INFO -> return
            Log.DEBUG -> if (!Prefs.verboseLogging) return
        }
        if (message != null)
            if (priority == Log.ERROR)
                Crashlytics.log(Log.ERROR, "Frost", message)
            else
                Crashlytics.log(message)
        if (t != null) Crashlytics.logException(t)
    }
}