mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-09 11:20:15 +08:00
添加日志工具类
This commit is contained in:
parent
f2bd0d2ae3
commit
0229dbe0df
@ -4,6 +4,6 @@ import org.slf4j.Logger
|
||||
|
||||
interface Slf4j {
|
||||
val log: Logger
|
||||
val logger: Logger get() = log
|
||||
val sfl4j: Logger get() = log
|
||||
val logger get() = log
|
||||
val sfl4j get() = log
|
||||
}
|
9
log/src/main/kotlin/cn/tursom/log/TrySlf4j.kt
Normal file
9
log/src/main/kotlin/cn/tursom/log/TrySlf4j.kt
Normal file
@ -0,0 +1,9 @@
|
||||
package cn.tursom.log
|
||||
|
||||
import org.slf4j.Logger
|
||||
|
||||
interface TrySlf4j {
|
||||
val log: Logger?
|
||||
val logger get() = log
|
||||
val sfl4j get() = log
|
||||
}
|
@ -3,11 +3,17 @@ package cn.tursom.log.impl
|
||||
import cn.tursom.log.Slf4j
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
|
||||
class Slf4jImpl(name: String? = null) : Slf4j {
|
||||
override val log: Logger = LoggerFactory.getLogger(name ?: if (this::class.java != Slf4jImpl::class.java) {
|
||||
val clazz = this::class
|
||||
constructor(clazz: Class<*>?) : this(clazz?.name)
|
||||
constructor(clazz: KClass<*>?) : this(clazz?.jvmName?.let {
|
||||
if (clazz.isCompanion) it.dropLast(10) else it
|
||||
})
|
||||
|
||||
override val log: Logger = LoggerFactory.getLogger(name ?: if (this.javaClass != Slf4jImpl::class.java) {
|
||||
val clazz = this.javaClass.kotlin
|
||||
clazz.jvmName.let {
|
||||
if (clazz.isCompanion) it.dropLast(10) else it
|
||||
}
|
||||
|
27
log/src/main/kotlin/cn/tursom/log/impl/TrySlf4jImpl.kt
Normal file
27
log/src/main/kotlin/cn/tursom/log/impl/TrySlf4jImpl.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package cn.tursom.log.impl
|
||||
|
||||
import cn.tursom.log.TrySlf4j
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
|
||||
class TrySlf4jImpl(name: String? = null) : TrySlf4j {
|
||||
constructor(clazz: Class<*>?) : this(clazz?.name)
|
||||
constructor(clazz: KClass<*>?) : this(clazz?.jvmName?.let {
|
||||
if (clazz.isCompanion) it.dropLast(10) else it
|
||||
})
|
||||
|
||||
override val log: Logger? = try {
|
||||
LoggerFactory.getLogger(name ?: if (this.javaClass != TrySlf4jImpl::class.java) {
|
||||
val clazz = this.javaClass.kotlin
|
||||
clazz.jvmName.let {
|
||||
if (clazz.isCompanion) it.dropLast(10) else it
|
||||
}
|
||||
} else {
|
||||
throw NotImplementedError("")
|
||||
})
|
||||
} catch (e: Throwable) {
|
||||
null
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
dependencies {
|
||||
implementation project(":")
|
||||
compileOnly project(":log")
|
||||
compileOnly group: 'org.slf4j', name: 'slf4j-api', version: '1.7.29'
|
||||
}
|
Loading…
Reference in New Issue
Block a user