mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Simplify logger structure
This commit is contained in:
parent
1dee5fe075
commit
1a4ad94d20
@ -2,13 +2,11 @@ package net.mamoe.mirai.utils
|
||||
|
||||
import android.util.Log
|
||||
|
||||
actual typealias PlatformLogger = AndroidLogger
|
||||
|
||||
/**
|
||||
* Android 平台的默认的日志记录器, 使用 [Log]
|
||||
* 不应该直接构造这个类的实例. 需使用 [DefaultLogger]
|
||||
*/
|
||||
open class AndroidLogger(override val identity: String? = "Mirai") : MiraiLoggerPlatformBase() {
|
||||
actual open class PlatformLogger actual constructor(override val identity: String?) : MiraiLoggerPlatformBase() {
|
||||
override fun verbose0(any: Any?) {
|
||||
Log.v(identity, any?.toString() ?: "")
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ var DefaultLogger: (identity: String?) -> MiraiLogger = { PlatformLogger(it) }
|
||||
* 在 _JVM 控制台_ 端的实现为 [println]
|
||||
* 在 _Android_ 端的实现为 [android.util.Log]
|
||||
*
|
||||
* 不应该直接构造这个类的实例. 请使用 [DefaultLogger]
|
||||
* 不应该直接构造这个类的实例. 请使用 [DefaultLogger], 或使用默认的顶层日志记录 [MiraiLogger.Companion]
|
||||
*/
|
||||
expect open class PlatformLogger @JvmOverloads internal constructor(identity: String? = "Mirai") : MiraiLoggerPlatformBase
|
||||
|
||||
@ -35,7 +35,7 @@ fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch = Mir
|
||||
*/
|
||||
interface MiraiLogger {
|
||||
/**
|
||||
* 顶层日志记录器
|
||||
* 顶层日志记录器.
|
||||
*/
|
||||
companion object : MiraiLogger by DefaultLogger("Mirai")
|
||||
|
||||
@ -146,13 +146,14 @@ object SilentLogger : PlatformLogger() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun SimpleLogger(logger: (String?, Throwable?) -> Unit): SimpleLogger = SimpleLogger(null, logger)
|
||||
|
||||
/**
|
||||
* 简易日志记录, 所有类型日志都会被重定向 [logger]
|
||||
*/
|
||||
class SimpleLogger(override val identity: String?, private val logger: (String?, Throwable?) -> Unit) : MiraiLoggerPlatformBase() {
|
||||
companion object {
|
||||
operator fun invoke(logger: (String?, Throwable?) -> Unit): SimpleLogger = SimpleLogger(null, logger)
|
||||
}
|
||||
|
||||
override fun verbose0(any: Any?) = logger(any?.toString(), null)
|
||||
override fun verbose0(message: String?, e: Throwable?) = logger(message, e)
|
||||
override fun debug0(any: Any?) = logger(any?.toString(), null)
|
||||
|
@ -3,13 +3,11 @@ package net.mamoe.mirai.utils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
actual typealias PlatformLogger = Console
|
||||
|
||||
/**
|
||||
* JVM 控制台日志实现
|
||||
*/
|
||||
open class Console @JvmOverloads internal constructor(
|
||||
override val identity: String? = "Mirai"
|
||||
actual open class PlatformLogger @JvmOverloads internal actual constructor(
|
||||
override val identity: String?
|
||||
) : MiraiLoggerPlatformBase() {
|
||||
override fun verbose0(any: Any?) = println(any, LoggerTextFormat.RESET)
|
||||
override fun verbose0(message: String?, e: Throwable?) {
|
||||
|
Loading…
Reference in New Issue
Block a user