package com.rgt.superr.utils

import android.os.Environment
import com.rgt.superr.MyApplication
import com.rgt.superr.R
import com.rgt.superr.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)
    }
}