跳到主要内容

输出方式

选择默认 AIBuds 日志器使用的最低日志级别和唯一输出目标。

API 参考

框架

AIBudsLog.xcframework

声明

Swift
/// The current log configuration.
static var logConfiguration: LogConfiguration { get }

/// Configures log storage, rotation, and output behavior.
final class LogConfiguration: NSObject {
    /// The severity threshold. Defaults to `.info`.
    var level: LogLevel

    /// The active output destination. Defaults to `.xlfacility`.
    var destination: LogDestination

    /// Relative log directory under Documents. Defaults to `.aibuds/logs`.
    var logsDirectory: String

    /// Maximum single file size. Defaults to 10 MB.
    var maxFileSize: UInt64

    /// Maximum retained age in days. Defaults to 3.
    var logFileMaxAge: Int
}

请参阅 logConfigurationLogLevelLogDestination

日志级别

level 表示需要记录的最低严重级别,低于该级别的日志会被丢弃。

级别用途
.verbose细粒度执行过程追踪。
.debug开发阶段的诊断信息。
.info正常进度和运行信息。
.warn可能需要关注的情况。
.error发生失败,但 App 可能仍可继续运行。
.fatal可能导致 App 终止的严重失败。
.mute关闭全部日志输出。

输出目标

输出目标输出位置是否支持导出
.consoleXcode 调试控制台
.oslogger通过 os_log 写入 Apple 统一日志
.file配置的 Documents 相对目录下的文件
.xlfacilityAIBudsXLFacility 持久化插件安装插件后支持

使用示例

Swift
import AIBudsLog
import AIBudsXLFacility

let configuration = AIBudsLogSDK.logConfiguration
configuration.level = .debug
configuration.destination = .xlfacility
configuration.logFileMaxAge = 7

AIBudsLogSDK.setXLFacilityPlugin(XLFacilitySDK.shared)

AIBudsLogSDK.logService.info(
    "SDK configured",
    subsystem: "com.example.app",
    category: "startup"
)

注意事项

  • 输出目标选择为进程级设置,会替换此前目标,并非同时启用多个输出。
  • logsDirectory 接收 Documents 相对路径,SDK 会移除开头的斜杠。
  • maxFileSizelogFileMaxAge 小于或等于零的值会被忽略。
  • 公开 SDK 不提供远程服务器日志配置,也不提供分类启用/禁用开关。