mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-07 04:57:27 +08:00
[+] Better logging
This commit is contained in:
@@ -82,6 +82,12 @@ operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) =
|
||||
(if (this is MutableMap) this else toMutableMap()).apply { putAll(map) }
|
||||
operator fun <K, V> MutableMap<K, V>.plusAssign(map: Map<K, V>) { putAll(map) }
|
||||
|
||||
// Strings
|
||||
operator fun Str.get(range: IntRange) = substring(range.first, (range.last + 1).coerceAtMost(length))
|
||||
operator fun Str.get(start: Int, end: Int) = substring(start, end.coerceAtMost(length))
|
||||
fun Str.center(width: Int, padChar: Char = ' ') = padStart((length + width) / 2, padChar).padEnd(width, padChar)
|
||||
|
||||
// Coroutine
|
||||
suspend fun <T> async(block: suspend kotlinx.coroutines.CoroutineScope.() -> T): T = withContext(Dispatchers.IO) { block() }
|
||||
|
||||
// Paths
|
||||
|
||||
@@ -9,17 +9,14 @@ import java.io.File
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
class AquaServerApplication
|
||||
class Entry
|
||||
|
||||
/**
|
||||
* Main method, entry point of the application
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
// If data/ is not found, create it
|
||||
File("data").mkdirs()
|
||||
|
||||
// Run the application
|
||||
val ctx = SpringApplication.run(AquaServerApplication::class.java, *args)
|
||||
val ctx = SpringApplication.run(Entry::class.java, *args)
|
||||
|
||||
// Start the AimeDbServer
|
||||
val aimeDbServer = ctx.getBean(AimeDbServer::class.java)
|
||||
@@ -28,4 +25,5 @@ fun main(args: Array<String>) {
|
||||
// Start the AutoChecker
|
||||
val checker = ctx.getBean(AutoChecker::class.java)
|
||||
checker.check()
|
||||
}
|
||||
}
|
||||
|
||||
44
src/main/java/icu/samnyan/aqua/spring/AquaLogging.kt
Normal file
44
src/main/java/icu/samnyan/aqua/spring/AquaLogging.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
package icu.samnyan.aqua.spring
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent
|
||||
import ch.qos.logback.core.pattern.CompositeConverter
|
||||
import ext.center
|
||||
import ext.get
|
||||
import org.springframework.boot.ansi.AnsiColor
|
||||
import org.springframework.boot.ansi.AnsiOutput
|
||||
|
||||
private const val PROJECT_PACKAGE_PREFIX = "icu.samnyan.aqua"
|
||||
private const val SEGA_PACKAGE_PREFIX = "icu.samnyan.aqua.sega"
|
||||
private val SYSTEM_COLOR = AnsiColor.WHITE
|
||||
private val SEGA_COLOR = AnsiColor.MAGENTA
|
||||
private val MISC_COLOR = AnsiColor.BRIGHT_BLUE
|
||||
|
||||
class LoggerComponent : CompositeConverter<ILoggingEvent>() {
|
||||
override fun transform(event: ILoggingEvent, input: String): String {
|
||||
val (str, clr) = if (event.loggerName.startsWith(PROJECT_PACKAGE_PREFIX)) {
|
||||
val sub = event.loggerName.substring(PROJECT_PACKAGE_PREFIX.length + 1)
|
||||
if (sub.startsWith("sega")) sub.substring(5).substringBefore(".")[0, 6].padEnd(6).uppercase() to SEGA_COLOR
|
||||
else sub.substringBefore(".")[0, 6].padEnd(6).uppercase() to MISC_COLOR
|
||||
} else "SYSTEM" to SYSTEM_COLOR
|
||||
return AnsiOutput.toString(clr, str)
|
||||
}
|
||||
}
|
||||
|
||||
class LoggerClassColor : CompositeConverter<ILoggingEvent>() {
|
||||
override fun transform(event: ILoggingEvent, rawInput: String): String {
|
||||
var input = rawInput
|
||||
val clr = when {
|
||||
event.loggerName.startsWith(SEGA_PACKAGE_PREFIX) -> {
|
||||
input = event.loggerName.substring(SEGA_PACKAGE_PREFIX.length + 1)
|
||||
SEGA_COLOR
|
||||
}
|
||||
event.loggerName.startsWith(PROJECT_PACKAGE_PREFIX) -> {
|
||||
input = event.loggerName.substring(PROJECT_PACKAGE_PREFIX.length + 1)
|
||||
MISC_COLOR
|
||||
}
|
||||
else -> SYSTEM_COLOR
|
||||
}
|
||||
input = input[0, 40].padEnd(40)
|
||||
return AnsiOutput.toString(clr, input)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user