Change logger loading method

This commit is contained in:
Karlatemp 2020-06-22 12:32:33 +08:00
parent b3f846ed16
commit 2620d323e6
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 11 additions and 14 deletions

View File

@ -13,18 +13,26 @@ package net.mamoe.mirai.console.pure
//import net.mamoe.mirai.console.utils.MiraiConsoleFrontEnd //import net.mamoe.mirai.console.utils.MiraiConsoleFrontEnd
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.MiraiConsoleFrontEnd import net.mamoe.mirai.console.MiraiConsoleFrontEnd
import net.mamoe.mirai.utils.DefaultLogger
import net.mamoe.mirai.utils.DefaultLoginSolver import net.mamoe.mirai.utils.DefaultLoginSolver
import net.mamoe.mirai.utils.LoginSolver import net.mamoe.mirai.utils.LoginSolver
import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.PlatformLogger
import org.fusesource.jansi.Ansi import org.fusesource.jansi.Ansi
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
private val ANSI_RESET = Ansi().reset().toString()
internal val LoggerCreator: (identity: String?) -> MiraiLogger = {
PlatformLogger(identity = it, output = { line ->
ConsoleUtils.lineReader.printAbove(line + ANSI_RESET)
})
}
@Suppress("unused") @Suppress("unused")
object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd { object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd {
private val globalLogger = DefaultLogger("Mirai") private val globalLogger = LoggerCreator("Mirai")
private val cachedLoggers = ConcurrentHashMap<String, MiraiLogger>() private val cachedLoggers = ConcurrentHashMap<String, MiraiLogger>()
// companion object { // companion object {
@ -49,7 +57,7 @@ object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd {
override fun loggerFor(identity: String?): MiraiLogger { override fun loggerFor(identity: String?): MiraiLogger {
identity?.apply { identity?.apply {
return cachedLoggers.computeIfAbsent(this, DefaultLogger) return cachedLoggers.computeIfAbsent(this, LoggerCreator)
} }
return globalLogger return globalLogger
} }
@ -82,7 +90,6 @@ object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd {
} }
) )
} }
} }
/* /*

View File

@ -36,18 +36,8 @@ object MiraiConsolePureLoader {
} }
} }
private val ANSI_RESET = Ansi().reset().toString()
internal fun overrideLoggingSystem() {
DefaultLogger = {
PlatformLogger(identity = it, output = { line ->
ConsoleUtils.lineReader.printAbove(line + ANSI_RESET)
})
}
}
internal fun startup() { internal fun startup() {
overrideLoggingSystem()
MiraiConsoleInitializer.init(MiraiConsolePure) MiraiConsoleInitializer.init(MiraiConsolePure)
startConsoleThread() startConsoleThread()
} }