MiraiLogger

interface MiraiLogger

日志记录器.

Mirai 日志系统

Mirai 内建简单的日志系统, 即 MiraiLogger. MiraiLogger 的实现有 SimpleLogger, PlatformLogger, SilentLogger.

MiraiLogger 仅能处理简单的日志任务, 通常推荐使用 org.slf4j.Logger, org.apache.logging.log4j.Logger 等日志库.

使用第三方日志库接管 Mirai 日志系统

使用 LoggerAdapters, 将第三方日志 Logger 转为 MiraiLogger. 然后通过 MiraiLogger.setDefaultLoggerCreator 全局覆盖日志.

实现或使用 MiraiLogger

不建议实现或使用 MiraiLogger. 请优先考虑使用上述第三方框架. MiraiLogger 仅应用于兼容旧版本代码.

See also

简易 logger, 它将所有的日志记录操作都转移给 lambda (String?, Throwable?) -> Unit

各个平台下的默认日志记录实现.

忽略任何日志记录操作的 logger 实例.

平台通用基础实现. 若 Mirai 自带的日志系统无法满足需求, 请继承这个类并实现其抽象函数.

Types

Companion
Link copied to clipboard
object Companion
Factory
Link copied to clipboard
interface Factory

可以 service 实现的方式覆盖.

Functions

call
Link copied to clipboard
open fun call(priority: SimpleLogger.LogPriority, message: String? = null, e: Throwable? = null)

根据优先级调用对应函数

debug
Link copied to clipboard
abstract fun debug(message: String?)

记录一个 调试 级别的日志.

open fun debug(e: Throwable?)
abstract fun debug(message: String?, e: Throwable?)
error
Link copied to clipboard
abstract fun error(message: String?)

记录一个 错误 级别的日志.

open fun error(e: Throwable?)
abstract fun error(message: String?, e: Throwable?)
info
Link copied to clipboard
abstract fun info(message: String?)

记录一个 信息 级别的日志.

open fun info(e: Throwable?)
abstract fun info(message: String?, e: Throwable?)
plus
Link copied to clipboard
open operator fun <T : MiraiLogger> plus(follower: T): T

添加一个 follower, 返回 follower 它只会把 this 的属性 MiraiLogger.follower 修改为这个函数的参数 follower, 然后返回这个参数. 若 MiraiLogger.follower 已经有值, 则会替换掉这个值.

verbose
Link copied to clipboard
abstract fun verbose(message: String?)

记录一个 verbose 级别的日志. 无关紧要的, 经常大量输出的日志应使用它.

open fun verbose(e: Throwable?)
abstract fun verbose(message: String?, e: Throwable?)
warning
Link copied to clipboard
abstract fun warning(message: String?)

记录一个 警告 级别的日志.

open fun warning(e: Throwable?)
abstract fun warning(message: String?, e: Throwable?)

Properties

follower
Link copied to clipboard
open var follower: MiraiLogger?

随从. 在 this 中调用所有方法后都应继续往 follower 传递调用. follower 的存在可以让一次日志被多个日志记录器记录.

identity
Link copied to clipboard
abstract val identity: String?

日志的标记. 在 Mirai 中, identity 可为

isDebugEnabled
Link copied to clipboard
open val isDebugEnabled: Boolean

当 DEBUG 级别的日志启用时返回 true

isEnabled
Link copied to clipboard
abstract val isEnabled: Boolean

获取 MiraiLogger 是否已开启

isErrorEnabled
Link copied to clipboard
open val isErrorEnabled: Boolean

当 ERROR 级别的日志启用时返回 true

isInfoEnabled
Link copied to clipboard
open val isInfoEnabled: Boolean

当 INFO 级别的日志启用时返回 true

isVerboseEnabled
Link copied to clipboard
open val isVerboseEnabled: Boolean

当 VERBOSE 级别的日志启用时返回 true.

isWarningEnabled
Link copied to clipboard
open val isWarningEnabled: Boolean

当 WARNING 级别的日志启用时返回 true

Inheritors

MiraiLoggerPlatformBase
Link copied to clipboard
SingleFileLogger
Link copied to clipboard

Extensions

debug
Link copied to clipboard
inline fun MiraiLogger.debug(message: () -> String?)
inline fun MiraiLogger.debug(message: () -> String?, e: Throwable?)
error
Link copied to clipboard
inline fun MiraiLogger.error(message: () -> String?)
inline fun MiraiLogger.error(message: () -> String?, e: Throwable?)
info
Link copied to clipboard
inline fun MiraiLogger.info(message: () -> String?)
inline fun MiraiLogger.info(message: () -> String?, e: Throwable?)
verbose
Link copied to clipboard
inline fun MiraiLogger.verbose(message: () -> String)
inline fun MiraiLogger.verbose(message: () -> String, e: Throwable?)
warning
Link copied to clipboard
inline fun MiraiLogger.warning(message: () -> String?)
inline fun MiraiLogger.warning(message: () -> String?, e: Throwable?)
withSwitch
Link copied to clipboard
fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch

给这个 logger 添加一个开关, 用于控制是否记录 log