|
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import java.util.logging.* |
|
|
|
import java.util.logging.* |
|
|
@ -32,16 +31,6 @@ object LogUtils { |
|
|
|
// 正常的日期格式 |
|
|
|
// 正常的日期格式 |
|
|
|
const val DATE_PATTERN_FULL = "yyyy-MM-dd HH:mm:ss" |
|
|
|
const val DATE_PATTERN_FULL = "yyyy-MM-dd HH:mm:ss" |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 为log设置等级 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param log |
|
|
|
|
|
|
|
* @param level |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun setLogLevel(log: Logger, level: Level) { |
|
|
|
|
|
|
|
log.level = level |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 为log添加控制台handler |
|
|
|
* 为log添加控制台handler |
|
|
|
* |
|
|
|
* |
|
|
@ -78,20 +67,13 @@ object LogUtils { |
|
|
|
fileHandler.level = level |
|
|
|
fileHandler.level = level |
|
|
|
fileHandler.formatter = object : Formatter() { |
|
|
|
fileHandler.formatter = object : Formatter() { |
|
|
|
override fun format(record: LogRecord): String { |
|
|
|
override fun format(record: LogRecord): String { |
|
|
|
|
|
|
|
|
|
|
|
// 设置文件输出格式 |
|
|
|
// 设置文件输出格式 |
|
|
|
return (getCurrentDateStr(DATE_PATTERN_FULL) + |
|
|
|
return (getCurrentDateStr(DATE_PATTERN_FULL) + ":" + record.message + "\n") |
|
|
|
" - Level:" + record.level.name.substring(0, 1) + |
|
|
|
|
|
|
|
" " + record.message + "\n") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: SecurityException) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
|
|
} catch (e: IOException) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
e.printStackTrace() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 添加输出文件handler |
|
|
|
// 添加输出文件handler |
|
|
|
log.addHandler(fileHandler) |
|
|
|
log.addHandler(fileHandler) |
|
|
|
} |
|
|
|
} |
|
|
|