adjust logger colors

This commit is contained in:
Him188 2019-10-31 23:11:55 +08:00
parent dd0501521c
commit e2171fd158
6 changed files with 44 additions and 42 deletions

View File

@ -63,10 +63,9 @@ kotlin {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("io.ktor:ktor-http-cio:$ktorVersion")
implementation("io.ktor:ktor-http:$ktorVersion")
implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-android:$ktorVersion")
}
languageSettings.enableLanguageFeature("InlineClasses")
@ -87,6 +86,10 @@ kotlin {
}
}
sourceSets["jvmTest"].apply {
kotlin.setSrcDirs(listOf("src/$name/kotlin"))
}
sourceSets.forEach {
it.languageSettings.enableLanguageFeature("InlineClasses")

View File

@ -60,7 +60,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
override suspend fun login(configuration: BotNetworkConfiguration): LoginResult = withContext(this.coroutineContext) {
TIMProtocol.SERVER_IP.forEach { ip ->
bot.logger.warning("Connecting server $ip")
bot.logger.info("Connecting server $ip")
socket = BotSocketAdapter(ip, configuration)
loginResult = CompletableDeferred()
@ -290,7 +290,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
}
}
bot.logger.info("Packet sent: $packet")
bot.logger.verbose("Packet sent: $packet")
PacketSentEvent(bot, packet).broadcast()
@ -338,7 +338,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
if (packet.serverIP != null) {//redirection
socket.close()
socket = BotSocketAdapter(packet.serverIP!!, socket.configuration)
bot.logger.warning("Redirecting to ${packet.serverIP}")
bot.logger.info("Redirecting to ${packet.serverIP}")
loginResult.complete(socket.resendTouch())
} else {//password submission
this.loginIP = packet.loginIP

View File

@ -1,32 +0,0 @@
package net.mamoe.mirai.utils
/**
* @author NaturalHG
*/
enum class LoggerTextFormat(private val format: String) {
RESET("\u001b[0m"),
BLUE("\u001b[0;34m"),
BLACK("\u001b[0;30m"),
DARK_GREY("\u001b[1;30m"),
LIGHT_BLUE("\u001b[1;34m"),
GREEN("\u001b[0;32m"),
LIGHT_GTEEN("\u001b[1;32m"),
CYAN("\u001b[0;36m"),
LIGHT_CYAN("\u001b[1;36m"),
RED("\u001b[0;31m"),
LIGHT_RED("\u001b[1;31m"),
PURPLE("\u001b[0;35m"),
LIGHT_PURPLE("\u001b[1;35m"),
BROWN("\u001b[0;33m"),
YELLOW("\u001b[1;33m"),
LIGHT_GRAY("\u001b[0;37m"),
WHITE("\u001b[1;37m");
override fun toString(): String {
//if(MiraiServer.getInstance().isUnix()){
return format
// }
// return "";
}
}

View File

@ -13,19 +13,19 @@ actual typealias PlatformLogger = Console
open class Console @JvmOverloads internal constructor(
override val identity: String? = null
) : MiraiLoggerPlatformBase() {
override fun verbose0(any: Any?) = println(any.toString(), LoggerTextFormat.LIGHT_GRAY)
override fun verbose0(any: Any?) = println(any.toString(), LoggerTextFormat.RESET)
override fun verbose0(message: String?, e: Throwable?) {
verbose(message.toString())
e?.printStackTrace()
}
override fun info0(any: Any?) = println(any.toString(), LoggerTextFormat.GREEN)
override fun info0(any: Any?) = println(any.toString(), LoggerTextFormat.LIGHT_GREEN)
override fun info0(message: String?, e: Throwable?) {
info(message.toString())
e?.printStackTrace()
}
override fun warning0(any: Any?) = println(any.toString(), LoggerTextFormat.YELLOW)
override fun warning0(any: Any?) = println(any.toString(), LoggerTextFormat.LIGHT_RED)
override fun warning0(message: String?, e: Throwable?) {
warning(message.toString())
e?.printStackTrace()
@ -38,7 +38,7 @@ open class Console @JvmOverloads internal constructor(
}
override fun debug0(any: Any?) {
println(any.toString(), LoggerTextFormat.CYAN)
println(any.toString(), LoggerTextFormat.LIGHT_CYAN)
}
override fun debug0(message: String?, e: Throwable?) {
@ -57,6 +57,32 @@ open class Console @JvmOverloads internal constructor(
}
}
/**
* @author NaturalHG
*/
internal enum class LoggerTextFormat(private val format: String) {
RESET("\u001b[0m"),
WHITE("\u001b[30m"),
RED("\u001b[31m"),
EMERALD_GREEN("\u001b[32m"),
GOLD("\u001b[33m"),
BLUE("\u001b[34m"),
PURPLE("\u001b[35m"),
GREEN("\u001b[36m"),
GRAY("\u001b[90m"),
LIGHT_RED("\u001b[91m"),
LIGHT_GREEN("\u001b[92m"),
LIGHT_YELLOW("\u001b[93m"),
LIGHT_BLUE("\u001b[94m"),
LIGHT_PURPLE("\u001b[95m"),
LIGHT_CYAN("\u001b[96m")
;
override fun toString(): String = format
}
@Suppress("unused")
val Throwable.stacktraceString: String
get() = ByteArrayOutputStream().also { printStackTrace(PrintStream(it)) }.toString()

View File

@ -0,0 +1,5 @@
fun main() {
repeat(100) {
println("\u001b[1;${it}m" + it)
}
}