package library

import com.bearya.kids.BuildConfig
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.DiskLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import com.orhanobut.logger.CsvFormatStrategy
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

object LoggerComponent {

    fun init() {
        val formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)
                .methodCount(5)
                .tag("LOGGER")
                .build()

        Logger.addLogAdapter(object : AndroidLogAdapter(formatStrategy) {
            override fun isLoggable(priority: Int, tag: String?): Boolean {
                return BuildConfig.DEBUG
            }
        })

        val csvFormatStrategy = CsvFormatStrategy.newBuilder()
                .tag("LOGGER")
                .date(Date())
                .dateFormat(SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS", Locale.CHINA))
                .build()

        Logger.addLogAdapter(object : DiskLogAdapter(csvFormatStrategy) {
            override fun isLoggable(priority: Int, tag: String?): Boolean {
                return BuildConfig.DEBUG.not()
            }
        })
    }

}