package com.ntels.product.chatbot.util

import android.util.Log
import com.hanwha.morakmorak.BuildConfig
import timber.log.Timber

/**
 * Created by aaron on 2018-05-31
 */

class AppLogger {

    companion object {
        private const val TAG = "Aaron"
        private const val MAX_LOG_LENGTH = 4000

        @JvmStatic fun init() {
            if (BuildConfig.DEBUG) {
                Timber.plant(object : Timber.DebugTree() {
                    var logLocation: String? = null

                    override fun createStackElementTag(element: StackTraceElement): String {
                        logLocation = "(" + element.fileName + ":" + element.lineNumber + ") "
                        return TAG
                    }

                    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
                        if (message.length < MAX_LOG_LENGTH) {
                            if (priority == Log.ASSERT) Log.wtf(tag, logLocation + message)
                            else Log.println(priority, tag, logLocation + message)
                            return
                        }
                    }

                })
            } else {
                //Crashlytics.start();
                Timber.plant(ReleaseTree())
            }
        }

        @JvmStatic fun d(s: String, vararg objects: Any) {
            Timber.d(s, *objects)
        }

        @JvmStatic fun d(throwable: Throwable, s: String, vararg objects: Any) {
            Timber.d(throwable, s, *objects)
        }

        @JvmStatic fun i(s: String, vararg objects: Any) {
            Timber.i(s, *objects)
        }

        @JvmStatic fun i(throwable: Throwable, s: String, vararg objects: Any) {
            Timber.i(throwable, s, *objects)
        }

        @JvmStatic fun w(s: String, vararg objects: Any) {
            Timber.w(s, *objects)
        }

        @JvmStatic fun w(throwable: Throwable, s: String, vararg objects: Any) {
            Timber.w(throwable, s, *objects)
        }

        @JvmStatic fun e(s: String, vararg objects: Any) {
            Timber.e(s, *objects)
        }

        @JvmStatic fun e(throwable: Throwable, s: String, vararg objects: Any) {
            Timber.e(throwable, s, *objects)
        }
    }

}