Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
mzdluo123 2020-08-17 22:43:47 +08:00
commit ecd00f8c55
No known key found for this signature in database
GPG Key ID: 9F7BC2C154107A1D
6 changed files with 156 additions and 0 deletions

View File

@ -36,6 +36,10 @@ object Versions {
const val bintray = "1.8.5"
}
object Logging {
const val slf4j = "1.7.30"
const val log4j = "2.13.3"
}
}
@Suppress("unused")

View File

@ -108,6 +108,8 @@ kotlin {
//api(kotlin("stdlib-jdk8"))
//api(kotlin("stdlib-jdk7"))
api(kotlin("reflect"))
compileOnly("org.apache.logging.log4j:log4j-api:" + Versions.Logging.log4j)
compileOnly("org.slf4j:slf4j-api:" + Versions.Logging.slf4j)
api(ktor("client-core-jvm", Versions.Kotlin.ktor))
implementation(kotlinx("io-jvm", Versions.Kotlin.io))

View File

@ -0,0 +1,32 @@
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.utils
import net.mamoe.mirai.utils.internal.logging.JdkLogger
import net.mamoe.mirai.utils.internal.logging.Log4jLogger
import net.mamoe.mirai.utils.internal.logging.Slf4jLogger
@SinceMirai("1.2.0")
public object LoggerAdapters {
@JvmStatic
public fun java.util.logging.Logger.asMiraiLogger(): MiraiLogger {
return JdkLogger(this)
}
@JvmStatic
public fun org.apache.logging.log4j.Logger.asMiraiLogger(): MiraiLogger {
return Log4jLogger(this);
}
@JvmStatic
public fun org.slf4j.Logger.asMiraiLogger(): MiraiLogger {
return Slf4jLogger(this)
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.utils.internal.logging
import net.mamoe.mirai.utils.MiraiLoggerPlatformBase
import java.util.logging.Level
import java.util.logging.Logger
internal class JdkLogger(private val logger: Logger) : MiraiLoggerPlatformBase() {
override fun verbose0(message: String?, e: Throwable?) {
logger.log(Level.FINER, message, e)
}
override fun debug0(message: String?, e: Throwable?) {
logger.log(Level.FINEST, message, e)
}
override fun info0(message: String?, e: Throwable?) {
logger.log(Level.INFO, message, e)
}
override fun warning0(message: String?, e: Throwable?) {
logger.log(Level.WARNING, message, e)
}
override fun error0(message: String?, e: Throwable?) {
logger.log(Level.SEVERE, message, e)
}
override val identity: String?
get() = logger.name
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.utils.internal.logging
import net.mamoe.mirai.utils.MiraiLoggerPlatformBase
import org.apache.logging.log4j.Logger
internal class Log4jLogger(private val logger: Logger) : MiraiLoggerPlatformBase() {
override fun verbose0(message: String?, e: Throwable?) {
logger.trace(message, e)
}
override fun debug0(message: String?, e: Throwable?) {
logger.debug(message, e)
}
override fun info0(message: String?, e: Throwable?) {
logger.info(message, e)
}
override fun warning0(message: String?, e: Throwable?) {
logger.warn(message, e)
}
override fun error0(message: String?, e: Throwable?) {
logger.error(message, e)
}
override val identity: String?
get() = logger.name
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.utils.internal.logging
import net.mamoe.mirai.utils.MiraiLoggerPlatformBase
import org.slf4j.Logger
internal class Slf4jLogger(private val logger: Logger) : MiraiLoggerPlatformBase() {
override fun verbose0(message: String?, e: Throwable?) {
logger.trace(message, e)
}
override fun debug0(message: String?, e: Throwable?) {
logger.debug(message, e)
}
override fun info0(message: String?, e: Throwable?) {
logger.info(message, e)
}
override fun warning0(message: String?, e: Throwable?) {
logger.warn(message, e)
}
override fun error0(message: String?, e: Throwable?) {
logger.error(message, e)
}
override val identity: String?
get() = logger.name
}