-
Notifications
You must be signed in to change notification settings - Fork 39
Configuration
Tony Shen edited this page Oct 24, 2021
·
9 revisions
使用 L 时,至少需要 saf-log-core 模块。
如果需要使用 L 的 json() 方法,则需要一个 converter 模块。L 自带了 fastjson、gson 相关的 converter 模块。开发者也可以自己实现 Converter。
implementation 'com.github.fengzhizi715.SAF-Kotlin-log:core:<latest-version>'
implementation 'com.github.fengzhizi715.SAF-Kotlin-log:gson:<latest-version>'
可以在 Application 中配置 L 的初始化
object LogManager {
const val PREFIX_APP = "recycle_machine-app-"
const val SEVEN_DAYS:Long = 24*3600*1000*7
private val filePrinter: FilePrinter by lazy {
var sdcardPath = "/sdcard/recycle_machine"
val f = Environment.getExternalStorageDirectory()
if (f != null) {
sdcardPath = f.absolutePath + "/recycle_machine/app"
}
FileBuilder().folderPath(sdcardPath).fileNameGenerator(MTAFileNameGenerator(PREFIX_APP)).cleanStrategy(FileLastModifiedCleanStrategy(SEVEN_DAYS)).build()
}
@JvmStatic
fun initLog() {
configL {
converter = GsonConverter()
}.apply {
addPrinter(filePrinter)
}
}
}
另外,也可以配置 App Crash 日志到文件中
crashPrinter = FileBuilder().folderPath("/storage/emulated/0/crash_logs").build()
CrashUtils.init(tag = "crashTag",printer = crashPrinter, onCrashListener = object : CrashUtils.OnCrashListener {
override fun onCrash(crashInfo: String, e: Throwable) {
}
})