类型范围内的分类日志记录。
FelinePine 提供了一个易于使用的 API,用于在你的架构中设置日志记录和日志类别。
Apple 平台
Linux
使用 Swift Package Manager 通过仓库 URL 安装此库
https://github.com/brightdigit/FelinePine.git
使用最高至 1.0.0 的版本。
创建一个定义类别的 LoggingSystem
public enum BushelLogging: LoggingSystem {
public enum Category: String, CaseIterable {
case library
case data
case view
case machine
case application
case observation
case market
}
}
内部的 Category 枚举必须具有 RawType 类型为 String。 此外,如果你希望利用自动创建的 Logger 对象,那么你也应该实现 CaseIterable。
现在在任何类型中使用你的新 LoggingSystem
Feline 和 PineLoggingSystemLoggingSystem.Categoryinternal struct VirtualMachine: Loggable {
internal typealias LoggingSystemType = BushelLogging
internal static let loggingCategory: BushelLogging.Category = .machine
func run () {
Self.logger.debug("Starting Run")
...
}
...
}
你可以通过使用 Loggable 协议来创建一个在你的整个代码库中使用的协议来简化操作
public protocol BushelLoggable: FelinePine.Loggable where Self.LoggingSystemType == BushelLogging {}
现在你可以简单地使用新的 Loggable 类型
internal struct VirtualMachine: BushelLoggable {
internal static let loggingCategory: BushelLogging.Category = .machine
func run () {
Self.logger.debug("Starting Run")
...
}
}
更多文档可在 Swift Package Index 上找到。
此代码是在 MIT 许可下分发的。 有关更多信息,请参见 LICENSE 文件。