{"id":30697555,"url":"https://github.com/richardpiazza/occurrence","last_synced_at":"2026-03-08T21:27:15.776Z","repository":{"id":39617278,"uuid":"333416727","full_name":"richardpiazza/Occurrence","owner":"richardpiazza","description":"A swift logging library that integrates with `SwiftLog`","archived":false,"fork":false,"pushed_at":"2025-06-13T20:42:48.000Z","size":97,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-18T15:48:36.513Z","etag":null,"topics":["logger","logging","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/richardpiazza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-27T12:42:15.000Z","updated_at":"2025-06-13T19:56:13.000Z","dependencies_parsed_at":"2025-06-13T20:39:34.490Z","dependency_job_id":null,"html_url":"https://github.com/richardpiazza/Occurrence","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/richardpiazza/Occurrence","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardpiazza%2FOccurrence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardpiazza%2FOccurrence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardpiazza%2FOccurrence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardpiazza%2FOccurrence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richardpiazza","download_url":"https://codeload.github.com/richardpiazza/Occurrence/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardpiazza%2FOccurrence/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273258921,"owners_count":25073819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logger","logging","swift"],"created_at":"2025-09-02T09:12:50.466Z","updated_at":"2026-03-08T21:27:15.768Z","avatar_url":"https://github.com/richardpiazza.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Occurrence\n\nA multi-platform log handler for [swift-log](https://github.com/apple/swift-log).\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FOccurrence%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/richardpiazza/Occurrence)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FOccurrence%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/richardpiazza/Occurrence)\n\n## Usage\n\n\u003e SwiftLog provides a unified, performant, and ergonomic logging API that can be adopted by libraries and applications across the Swift ecosystem.\n\nThe thing SwiftLog does not provide is a `LogHandler` - any instance that consumes logs being generated by libraries and applications.\nThis is where **Occurrence** steps in. This package provides a SQLite backed storage mechanism to capture, query, and export logs.\nIn order to provide this functionality, a `LogHandler` must first be _bootstrapped_ into the logging system.\n**Occurrence** provides a convenience method to configure itself as the `LogHandler`:\n\n```swift\nOccurrence.bootstrap()\n```\n\nBootstrapping must be completed before the initialization of any `Logger` instance.\nTypically this is done at the very start of your application. For instance:\n\n```swift\n@main\nstruct MyApp: App {\n  init() {\n    Occurrence.bootstrap()\n    // … continued initialization.\n  }\n}\n```\n\nThat's everything needed to start capturing logs!\n\n## Queries \u0026 Exports\n\nCapturing logs is great, but somewhat useless if you can't _do_ anything with them.\nTo allow for observation, querying, and export of logging data, **Occurrence** defines `LogStreamer` and `LogProvider` instances.\n\n### LogStreamer\n\n```swift\nprotocol LogStreamer: Sendable {\n  var stream: AsyncStream\u003cLogger.Entry\u003e { get }\n  func log(_ entry: Logger.Entry)\n}\n```\n\nA `LogStream` provides an `AsyncStream` of `Logger.Entry` types as they are processed by framework.\nThese entries can easily be observed:\n\n```swift\nlet task = Task {\n  for await entry in Occurrence.logStreamer.stream {\n    // process entry\n  }\n}\n```\n\n### LogProvider\n\n```swift\nprotocol LogProvider: Sendable {\n    func log(_ entry: Logger.Entry)\n    func subsystems() -\u003e [Logger.Subsystem]\n    func entries(matching filter: Logger.Filter?, ascending: Bool, limit: UInt) -\u003e [Logger.Entry]\n    func purge(matching filter: Logger.Filter?)\n}\n```\n\nA `LogProvider` consumes log entries as they are registered and provides data about those entries as requested.\nVarious filters can be provided to fine-tune the results you're looking for.\n\n## Conveniences\n\n### `LogView`\n\nIf you are in a SwiftUI environment the `LogView` view provides a way to observe, manage, and export log entries.\nThis offers a prime example of how the `LogStreamer` and `LogProvider` types can be utilized within an application.\n\n### `LoggableError`\n\nA `LoggableError` is an `Error` type that can be easily converted to `Logger.Metadata`.\nMany standard error types have conformances for this protocol, including:\n* `CocoaError`\n* `DecodingError`\n* `EncodingError`\n* `URLError`\n\nThere are also extensions to the `Logger` instance that allow for passthrough of a `LoggableError` instance:\n\n```swift\n@LazyLogger(\"MyApp\") var logger: Logger\n\nenum AppError: LoggableError {\n  case badData\n}\n\nfunc throwingFunction() throws {\n  guard condition else {\n    throw logger.error(\"Condition not met.\", AppError.badData)\n  }\n}\n```\n\n### `LazyLogger`\n\nEvery `Logger` instance supplies a label (Internally Occurrence uses the type `Logger.Subsystem` for this).\nAs a convenience to creating a `Logger` reference, use the `LazyLogger` property wrapper which will create a Logger with the specific label (`Logger.Subsystem`).\n\n```swift\n@LazyLogger(\"LoggerLabel\") var logger: Logger\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardpiazza%2Foccurrence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichardpiazza%2Foccurrence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardpiazza%2Foccurrence/lists"}