pull/36/head
kunfei 5 years ago
parent 016e98f485
commit 1ce32423a9
  1. 3
      app/build.gradle
  2. 10
      app/src/main/java/io/legado/app/App.kt
  3. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  4. 5
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  5. 5
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  6. 63
      app/src/main/java/io/legado/app/utils/LogUtils.kt

@ -148,7 +148,4 @@ dependencies {
//
implementation 'com.jaredrummler:colorpicker:1.1.0'
//
implementation 'com.apkfuns.logutils:library:1.7.5'
implementation 'com.apkfuns.log2file:log2file:1.3.1'
}

@ -9,8 +9,6 @@ import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
import com.apkfuns.log2file.LogFileEngineFactory
import com.apkfuns.logutils.LogUtils
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
@ -18,15 +16,12 @@ import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp
import io.legado.app.help.CrashHandler
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.widget.page.ChapterProvider
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.isNightTheme
import java.io.File
@Suppress("DEPRECATION")
class App : Application() {
@ -48,11 +43,6 @@ class App : Application() {
super.onCreate()
INSTANCE = this
CrashHandler().init(this)
LogUtils.getLog2FileConfig()
.configLog2FileEnable(getPrefBoolean("recordLog"))
.configLog2FilePath(FileHelp.getCachePath() + File.separator + "logs" + File.separator)
.configLog2FileNameFormat("%d{yyyyMMdd}.log")
.configLogFileEngine(LogFileEngineFactory(this))
db = AppDatabase.createDatabase(INSTANCE)
packageManager.getPackageInfo(packageName, 0)?.let {
versionCode = it.versionCode

@ -4,10 +4,10 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import com.apkfuns.logutils.LogUtils
import io.legado.app.constant.Bus
import io.legado.app.help.ActivityHelp
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.LogUtils
import io.legado.app.utils.postEvent

@ -6,12 +6,11 @@ import android.view.View
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.apkfuns.logutils.LogUtils
import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefString
@ -41,7 +40,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
"downloadPath" -> BookHelp.upDownloadPath()
"recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog"))
"recordLog" -> LogUtils.upLevel()
}
}

@ -7,7 +7,6 @@ import android.view.MenuItem
import android.view.View
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.apkfuns.logutils.LogUtils
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseFragment
@ -23,7 +22,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.config.ConfigActivity
import io.legado.app.ui.config.ConfigViewModel
import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.LogUtils
import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
@ -86,7 +85,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
) {
when (key) {
"isNightTheme" -> App.INSTANCE.applyDayNight()
"recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog"))
"recordLog" -> LogUtils.upLevel()
"downloadPath" -> BookHelp.upDownloadPath()
}
}

@ -0,0 +1,63 @@
package io.legado.app.utils
import android.annotation.SuppressLint
import io.legado.app.App
import io.legado.app.help.FileHelp
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import java.util.logging.*
import java.util.logging.Formatter
object LogUtils {
const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"
fun d(tag: String, msg: String) {
logger.log(Level.INFO, "$tag $msg")
}
fun e(tag: String, msg: String) {
logger.log(Level.WARNING, "$tag $msg")
}
private val logger: Logger by lazy {
Logger.getGlobal().apply {
addHandler(fileHandler)
}
}
private val fileHandler by lazy {
FileHandler(FileHelp.getCachePath() + File.separator + "app.log", 1024, 2).apply {
formatter = object : Formatter() {
override fun format(record: LogRecord): String {
// 设置文件输出格式
return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n")
}
}
level = if (App.INSTANCE.getPrefBoolean("recordLog")) {
Level.INFO
} else {
Level.OFF
}
}
}
fun upLevel() {
fileHandler.level = if (App.INSTANCE.getPrefBoolean("recordLog")) {
Level.INFO
} else {
Level.OFF
}
}
/**
* 获取当前时间
*/
@SuppressLint("SimpleDateFormat")
fun getCurrentDateStr(pattern: String): String {
val date = Date()
val sdf = SimpleDateFormat(pattern)
return sdf.format(date)
}
}
Loading…
Cancel
Save