package com.base.scanqrclear.utils

import android.os.Environment
import com.base.scanqrclear.BuildConfig
import com.base.scanqrclear.MyApplication
import com.base.scanqrclear.R
import com.base.scanqrclear.utils.KotlinExt.toFormatTime2
import java.io.File

object WriteLogEx {
    private val logoDir by lazy(LazyThreadSafetyMode.NONE) {
        val appName = MyApplication.appContext.resources.getString(R.string.app_name)
        val log = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "${appName}_logo")
        if (!log.exists()) log.mkdirs()
        log
    }

    fun writeLogFile(key: String, log: String) {
        if (!BuildConfig.DEBUG) return
        val logName = key + "_" + System.currentTimeMillis().toFormatTime2() + ".txt"
        val logFile = File(logoDir, logName)
        logFile.createNewFile()
        logFile.writeText(log, Charsets.UTF_8)
    }
}