Type-wide categorized logging.
FelinePine provides an easy to use API for setting up logging and log categories across your architecture.
Apple Platforms
- Xcode 14.3.1 or later
- Swift 5.8 or later
- macOS 12 or later deployment targets
Linux
- Ubuntu 18.04 or later
- Swift 5.8 or later
Use the Swift Package Manager to install this library via the repository url:
https://github.com/brightdigit/FelinePine.git
Use version up to 1.0.0.
Create a LoggingSystem which defines the categories:
public enum BushelLogging: LoggingSystem {
public enum Category: String, CaseIterable {
case library
case data
case view
case machine
case application
case observation
case market
}
}The Category enum inside must have a RawType of String.
Additionally if you wish to take advantage of automatically created Logger object,
then you should also have to implment CaseIterable.
Now to use your new LoggingSystem in any type:
- Implement
FelineandPine - Define your
LoggingSystem - Define the
LoggingSystem.Category
internal struct VirtualMachine: Loggable {
internal typealias LoggingSystemType = BushelLogging
internal static let loggingCategory: BushelLogging.Category = .machine
func run () {
Self.logger.debug("Starting Run")
...
}
...
}You can simplify by using the Loggable protocol to create protocol to use throughout your codebase:
public protocol BushelLoggable: FelinePine.Loggable where Self.LoggingSystemType == BushelLogging {}Now you can simply use the new Loggable type:
internal struct VirtualMachine: BushelLoggable {
internal static let loggingCategory: BushelLogging.Category = .machine
func run () {
Self.logger.debug("Starting Run")
...
}
}Further documentation is available at the Swift Package Index.
This code is distributed under the MIT license. See the LICENSE file for more info.