package com.abbidot.baselibrary.util

import android.util.Log
import java.util.*

/**
 *Created  by .yzq on 2021/11/3/003.
 * @link
 * @description: 日志相关工具类
 */
class LogUtil {

    companion object {

        private const val TAG = "AbbiDot"

        private fun isLoggable(): Boolean {
            return AppUtils.isDebug()
        }

        fun i(tag: String, fmt: String, vararg args: Any) {
            if (isLoggable()) {
                Log.i(tag, format(fmt, *args))
            }
        }

        fun i(msg: String) {
            i(TAG, msg)
        }

        fun d(tag: String, fmt: String, vararg args: Any) {
            if (isLoggable()) {
                Log.d(tag, format(fmt, *args))
            }
        }

        fun d(msg: String) {
            d(TAG, msg)
        }

        fun w(tag: String, fmt: String, vararg args: Any) {
            if (isLoggable()) {
                Log.w(tag, format(fmt, *args))
            }
        }

        fun w(msg: String) {
            w(TAG, msg)
        }

        fun e(tag: String, fmt: String, vararg args: Any) {
            if (isLoggable()) {
                Log.e(tag, format(fmt, *args))
            }
        }

        fun e(msg: String) {
            e(TAG, msg)
        }

        fun e(tag: String, t: Throwable, fmt: String, vararg args: Any) {
            if (isLoggable()) {
                Log.e(tag, format(fmt, *args), t)
            }
        }

        private fun format(fmt: String, vararg args: Any): String {
            return if (args.isEmpty()) {
                fmt
            } else {
                String.format(Locale.getDefault(), fmt, *args)
            }
        }
    }
}