添加日志工具类

This commit is contained in:
tursom 2019-11-30 10:13:13 +08:00
parent d9b7b3a5d4
commit f2bd0d2ae3
5 changed files with 32 additions and 1 deletions

4
log/build.gradle Normal file
View File

@ -0,0 +1,4 @@
dependencies {
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61'
compileOnly group: 'org.slf4j', name: 'slf4j-api', version: '1.7.29'
}

View File

@ -0,0 +1,9 @@
package cn.tursom.log
import org.slf4j.Logger
interface Slf4j {
val log: Logger
val logger: Logger get() = log
val sfl4j: Logger get() = log
}

View File

@ -0,0 +1,17 @@
package cn.tursom.log.impl
import cn.tursom.log.Slf4j
import org.slf4j.Logger
import org.slf4j.LoggerFactory
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
clazz.jvmName.let {
if (clazz.isCompanion) it.dropLast(10) else it
}
} else {
throw NotImplementedError("")
})
}

View File

@ -2,4 +2,5 @@ rootProject.name = 'TursomServer'
include 'web', 'aop', 'database', 'database:database-async', 'utils', 'utils:xml', 'utils:async-http', 'web:netty-web'
include 'socket', 'socket:socket-async'
include 'AsyncSocket'
include 'log'

View File

@ -1,4 +1,4 @@
dependencies {
implementation project(":")
compileOnly group: 'org.slf4j', name: 'slf4j-api', version: '1.7.29'
compileOnly project(":log")
}