diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformLoggerAndroid.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformLoggerAndroid.kt index 9bd8b298d..9bc015143 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformLoggerAndroid.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformLoggerAndroid.kt @@ -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() ?: "") } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt index 7e4543401..1c8258e08 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt @@ -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") @@ -130,29 +130,21 @@ interface MiraiLogger { object SilentLogger : PlatformLogger() { override val identity: String? = null - override fun error0(any: Any?) { - } - - override fun debug0(any: Any?) { - } - - override fun warning0(any: Any?) { - } - - override fun verbose0(any: Any?) { - } - - override fun info0(any: Any?) { - } + override fun error0(any: Any?) = Unit + override fun debug0(any: Any?) = Unit + override fun warning0(any: Any?) = Unit + override fun verbose0(any: Any?) = Unit + override fun info0(any: Any?) = Unit } -@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) diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLoggerJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLoggerJvm.kt index 846500af2..b86576ce9 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLoggerJvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLoggerJvm.kt @@ -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?) {