Remove MiraiLogger.subLogger in mirai-core-api to overcome declaration clash on native

This commit is contained in:
Him188 2022-06-11 09:36:25 +01:00
parent fe0a4de368
commit 4230a6e84c
2 changed files with 19 additions and 20 deletions

View File

@ -10,8 +10,6 @@
package net.mamoe.mirai.internal.utils package net.mamoe.mirai.internal.utils
import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLogger
import kotlin.jvm.JvmName
import kotlin.native.CName
/** /**
* 内部添加 [Marker] 支持, 并兼容旧 [MiraiLogger] API. * 内部添加 [Marker] 支持, 并兼容旧 [MiraiLogger] API.
@ -39,16 +37,18 @@ internal fun Marker(name: String, vararg parents: Marker?): Marker {
internal val MiraiLogger.markerOrNull get() = (this as? MarkedMiraiLogger)?.marker internal val MiraiLogger.markerOrNull get() = (this as? MarkedMiraiLogger)?.marker
/** // This clashes with the same declaration in mirai-core (same package), for native.
* Create a marked logger whose marker is a child of this' marker. //
* ///**
* Calling [MarkedMiraiLogger.subLogger] if possible, and creating [MiraiLoggerMarkedWrapper] otherwise. // * Create a marked logger whose marker is a child of this' marker.
*/ // *
@JvmName("subLoggerImpl2") // * Calling [MarkedMiraiLogger.subLogger] if possible, and creating [MiraiLoggerMarkedWrapper] otherwise.
@CName("", "subLogger2") // */
internal fun MiraiLogger.subLogger(name: String): MiraiLogger { //@JvmName("subLoggerImpl2")
return subLoggerImpl(this, name) //@CName("", "subLogger2")
} //internal fun MiraiLogger.subLogger(name: String): MiraiLogger {
// return subLoggerImpl(this, name)
//}
// used by mirai-core // used by mirai-core
internal fun subLoggerImpl(origin: MiraiLogger, name: String): MiraiLogger { internal fun subLoggerImpl(origin: MiraiLogger, name: String): MiraiLogger {

View File

@ -16,12 +16,7 @@ import net.mamoe.mirai.utils.LoggerAdapters.asMiraiLogger
import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLogger
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach import kotlin.test.*
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertSame
internal class Log4j2LoggingTest { internal class Log4j2LoggingTest {
@BeforeTest @BeforeTest
@ -56,7 +51,7 @@ internal class Log4j2LoggingTest {
val parent = MiraiLogger.Factory.create(Log4j2LoggingTest::class, "test1") val parent = MiraiLogger.Factory.create(Log4j2LoggingTest::class, "test1")
val parentMarker = parent.cast().marker!! val parentMarker = parent.cast().marker!!
val child = parent.subLogger("sub") val child = subLoggerImpl(parent, "sub")
val childMarker = child.markerOrNull!! val childMarker = child.markerOrNull!!
assertEquals("test1", parentMarker.name) assertEquals("test1", parentMarker.name)
@ -90,3 +85,7 @@ internal class Log4j2LoggingTest {
} }
} }
} }
internal fun MiraiLogger.subLogger(s: String): MiraiLogger {
return subLoggerImpl(this, s)
}