输出方式
选择默认 AIBuds 日志器使用的最低日志级别和唯一输出目标。
API 参考
框架
AIBudsLog.xcframework
声明
- Swift
- Objective-C
/// 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
}/// The current log configuration.
@property(nonatomic, class, readonly, strong) AIBudsLogConfiguration *logConfiguration;
/// Configures log storage, rotation, and output behavior.
@interface AIBudsLogConfiguration : NSObject
/// The severity threshold. Defaults to `AIBudsLogLevelInfo`.
@property(nonatomic) AIBudsLogLevel level;
/// The active output destination. Defaults to XLFacility.
@property(nonatomic) AIBudsLogDestination destination;
/// Relative log directory under Documents. Defaults to `.aibuds/logs`.
@property(nonatomic, copy) NSString *logsDirectory;
/// Maximum single file size. Defaults to 10 MB.
@property(nonatomic) uint64_t maxFileSize;
/// Maximum retained age in days. Defaults to 3.
@property(nonatomic) NSInteger logFileMaxAge;
@end请参阅 logConfiguration、LogLevel 和 LogDestination。
日志级别
level 表示需要记录的最低严重级别,低于该级别的日志会被丢弃。
| 级别 | 用途 |
|---|---|
.verbose | 细粒度执行过程追踪。 |
.debug | 开发阶段的诊断信息。 |
.info | 正常进度和运行信息。 |
.warn | 可能需要关注的情况。 |
.error | 发生失败,但 App 可能仍可继续运行。 |
.fatal | 可能导致 App 终止的严重失败。 |
.mute | 关闭全部日志输出。 |
输出目标
| 输出目标 | 输出位置 | 是否支持导出 |
|---|---|---|
.console | Xcode 调试控制台 | 否 |
.oslogger | 通过 os_log 写入 Apple 统一日志 | 否 |
.file | 配置的 Documents 相对目录下的文件 | 是 |
.xlfacility | AIBudsXLFacility 持久化插件 | 安装插件后支持 |
使用示例
- Swift
- Objective-C
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"
)#import <AIBudsLog/AIBudsLog-Swift.h>
#import <AIBudsXLFacility/AIBudsXLFacility-Swift.h>
AIBudsLogConfiguration *configuration = AIBudsLogSDK.logConfiguration;
configuration.level = AIBudsLogLevelDebug;
configuration.destination = AIBudsLogDestinationXlfacility;
configuration.logFileMaxAge = 7;
[AIBudsLogSDK setXLFacilityPlugin:AIBudsXLFacilitySDK.shared];
[AIBudsLogSDK.logService info:@"SDK configured" subsystem:@"com.example.app" category:@"startup"];注意事项
- 输出目标选择为进程级设置,会替换此前目标,并非同时启用多个输出。
logsDirectory接收 Documents 相对路径,SDK 会移除开头的斜杠。maxFileSize和logFileMaxAge小于或等于零的值会被忽略。- 公开 SDK 不提供远程服务器日志配置,也不提供分类启用/禁用开关。