A swift logging library that integrates with SwiftLog.
During you app initialization, call Occurrence.bootstrap(). This will configure the Swift LoggingSystem to use Occurrence as a LogHandler.
As a convenience to creating a Logger reference, use the LazyLogger property wrapper which will create a Logger with the specific label (Logger.Subsystem).
@LazyLogger("LoggerLabel") var logger: LoggerOccurrence also offers the ability to observe logging events as they are happening. This can also be useful in the case where entries may need to be proxied to a third-party service.
// Combine
Occurrence.logStreamer
.publisher
.sink { entry in
// process entry
}
// async/await
let task = Task {
for await entry in Occurrence.logStreamer.stream {
// process entry
}
}Occurrence has many conveniences to enhance the overall logging experience.
The LoggableError protocol provides a way to easily convert errors to a Logger.Metadata representation.
There are also extensions to the Logger instance that allow for passthrough of a LoggableError instance:
@LazyLogger("MyApp") var logger: Logger
enum AppError: LoggableError {
case badData
}
func throwingFunction() throws {
guard condition else {
throw logger.error("Condition not met.", AppError.badData)
}
}