package com.easy.clean.utils

import android.os.Environment
import com.easy.clean.MyApplication
import com.easy.clean.R
import com.easy.clean.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) {
        val logName = key + "_" + System.currentTimeMillis().toFormatTime2() + ".txt"
        val logFile = File(logoDir, logName)
        logFile.createNewFile()
        logFile.writeText(log, Charsets.UTF_8)
    }
}