Add migration helper for MiraiLogger

This commit is contained in:
Him188 2020-12-18 14:14:38 +08:00
parent 20bc17ee43
commit 9c22de03e0

View File

@ -17,29 +17,41 @@ import net.mamoe.mirai.Bot
import kotlin.contracts.InvocationKind.AT_MOST_ONCE
import kotlin.contracts.contract
@Suppress("DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@Deprecated(
"Use MiraiLogger.create",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith(
"{ identity: String? -> MiraiLogger.create(identity) }",
"net.mamoe.mirai.utils.MiraiLogger"
)
)
@PlannedRemoval("2.0-M2")
public var DefaultLogger: (identity: String?) -> MiraiLogger
@Deprecated(
"Create lambda by yourself.",
ReplaceWith("{ identity: String? -> MiraiLogger.create(identity) }", "net.mamoe.mirai.utils.MiraiLogger"),
level = DeprecationLevel.ERROR,
)
get() = { MiraiLogger.create(it) }
@Deprecated(
"Use MiraiLogger.setDefaultLoggerCreator",
replaceWith = ReplaceWith("MiraiLogger.setDefaultLoggerCreator(value)", "net.mamoe.mirai.utils.MiraiLogger"),
level = DeprecationLevel.ERROR,
)
set(value) = MiraiLogger.setDefaultLoggerCreator(value)
/**
* 用于创建默认的日志记录器. 在一些需要使用日志的 Mirai 的组件, [Bot], 都会通过这个函数构造日志记录器.
*
* 可直接修改这个变量的值来重定向日志输出.
*
* **注意:** 请务必将所有的输出定向到日志记录系统, 否则在某些情况下 ( web 控制台中) 将无法接收到输出
*
* **注意:** 请为日志做好分类, 即不同的模块使用不同的 [MiraiLogger].
* , [Bot] 中使用 `identity` "Bot(qqId)" [MiraiLogger]
* [Bot] 的网络处理中使用 `identity` "BotNetworkHandler".
*
* Java 调用: `Utils.getDefaultLogger().invoke(identity)`
*/
@PlannedRemoval("2.0-M2")
@Suppress("DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "NOTHING_TO_INLINE", "FunctionName")
@Deprecated(
"Use MiraiLogger.create",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("MiraiLogger.create(identity)", "net.mamoe.mirai.utils.MiraiLogger")
)
@PlannedRemoval("2.0-M2")
public var DefaultLogger: (identity: String?) -> MiraiLogger
get() = { MiraiLogger.create(it) }
set(value) = MiraiLogger.setDefaultLoggerCreator(value)
@kotlin.internal.HidesMembers
@JvmSynthetic
public inline fun DefaultLogger(identity: String?): MiraiLogger = MiraiLogger.create(identity)
/**
* 给这个 logger 添加一个开关, 用于控制是否记录 log