添加更加灵活的日志预配置

This commit is contained in:
tursom 2019-12-15 23:56:19 +08:00
parent 62131beaa0
commit 2512e49fa2
2 changed files with 28 additions and 7 deletions

View File

@ -35,7 +35,7 @@ object LogbackPattern {
val highlight = ColorEnum.HIGHLIGHT
}
inline fun color(action: Color.() -> ColorEnum) = Color.action()
inline fun color(action: Color.() -> ColorEnum) = Color.action().toString()
const val nextLine = "n"
const val logger = "c"

View File

@ -1,3 +1,5 @@
@file:Suppress("unused")
package cn.tursom.log
import ch.qos.logback.classic.LoggerContext
@ -60,12 +62,31 @@ fun configureLogbackDirectly(logDir: String, filePrefix: String) {
}
val defaultColorfulPattern = LogbackPattern.make {
+color { green }(+date)["yyyy-MM-dd HH:mm:ss.SSS"] + " " +
+color { magenta }("[${+thread.right(15, 15)}]") + " " +
+color { highlight }(+level.left(5)) + " " +
+color { cyan }("[${+logger["20"].right(20, 20)}]") + " - " +
//+color { yellow }(+line.left(3, 3) + " " + +clazz.left(10, 10)) + " " +
+color { green }(+date["yyyy-MM-dd HH:mm:ss.SSS"]) + " " +
+color { magenta }("[${+thread}]") + " " +
+color { highlight }(+level) + " " +
+color { cyan }("[${+line + " " + +logger["20"]}]") + " - " +
+color { highlight }(+message) +
+nextLine
"\n"
}
val defaultFormatPattern = LogbackPattern.make {
+color { green }(+date["yyyy-MM-dd HH:mm:ss.SSS"]) + " " +
+color { magenta }("[${+thread.right(10, 10)}]") + " " +
+color { highlight }(+level.left(5, 5)) + " " +
+color { cyan }("[${+line.right(3) + " " + +logger["20"].right(20, 20)}]") + " - " +
+color { highlight }(+message) +
"\n"
}
val simpPattern = LogbackPattern.make {
+color { green }(+date["HH:mm:ss"]) + " " +
//+color { magenta }("[${+thread.right(null, 5)}]") + " " +
+color { highlight }(+level) + " " +
+color { cyan }("[${+logger["1"]}]") + " - " +
+color { highlight }(+message) +
"\n"
}
fun colorfulConsoleLogger(appender: OutputStreamAppender<*>, pattern: String = defaultColorfulPattern) {
@ -86,4 +107,4 @@ fun colorfulConsoleLogger(pattern: String = defaultColorfulPattern) {
colorfulConsoleLogger(it, pattern)
}
}
}
}