mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Change logger loading method
This commit is contained in:
parent
b3f846ed16
commit
2620d323e6
@ -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 {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user