mirror of https://github.com/hykilpikonna/AquaDX
[+] Better logging
parent
f1461f905d
commit
02b78320ec
|
@ -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) }
|
(if (this is MutableMap) this else toMutableMap()).apply { putAll(map) }
|
||||||
operator fun <K, V> MutableMap<K, V>.plusAssign(map: Map<K, V>) { 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() }
|
suspend fun <T> async(block: suspend kotlinx.coroutines.CoroutineScope.() -> T): T = withContext(Dispatchers.IO) { block() }
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
|
|
|
@ -9,17 +9,14 @@ import java.io.File
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
class AquaServerApplication
|
class Entry
|
||||||
|
|
||||||
/**
|
|
||||||
* Main method, entry point of the application
|
|
||||||
*/
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
// If data/ is not found, create it
|
// If data/ is not found, create it
|
||||||
File("data").mkdirs()
|
File("data").mkdirs()
|
||||||
|
|
||||||
// Run the application
|
// Run the application
|
||||||
val ctx = SpringApplication.run(AquaServerApplication::class.java, *args)
|
val ctx = SpringApplication.run(Entry::class.java, *args)
|
||||||
|
|
||||||
// Start the AimeDbServer
|
// Start the AimeDbServer
|
||||||
val aimeDbServer = ctx.getBean(AimeDbServer::class.java)
|
val aimeDbServer = ctx.getBean(AimeDbServer::class.java)
|
||||||
|
@ -28,4 +25,5 @@ fun main(args: Array<String>) {
|
||||||
// Start the AutoChecker
|
// Start the AutoChecker
|
||||||
val checker = ctx.getBean(AutoChecker::class.java)
|
val checker = ctx.getBean(AutoChecker::class.java)
|
||||||
checker.check()
|
checker.check()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||||
|
<conversionRule conversionWord="cmp" converterClass="icu.samnyan.aqua.spring.LoggerComponent" />
|
||||||
|
<conversionRule conversionWord="cls" converterClass="icu.samnyan.aqua.spring.LoggerClassColor" />
|
||||||
|
<conversionRule conversionWord="correlationId" converterClass="org.springframework.boot.logging.logback.CorrelationIdConverter" />
|
||||||
|
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||||
|
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||||
|
|
||||||
|
<!-- Define the log file name and path -->
|
||||||
|
<property name="LOG_FILE" value="logs/AquaDX.log"/>
|
||||||
|
|
||||||
|
<!-- Console appender with custom pattern -->
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%clr(%date{MM-dd HH:mm:ss}){magenta} %clr(${LOG_LEVEL_PATTERN:-%-5p}) %cmp | %cls(%-40.40logger{39}) : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- File appender with JSON layout -->
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${LOG_FILE}</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern>
|
||||||
|
<maxHistory>7</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Log levels -->
|
||||||
|
<logger name="org.springframework" level="INFO"/>
|
||||||
|
|
||||||
|
<!-- Root logger -->
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="FILE"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue