{"id":20382951,"url":"https://github.com/binaryscraping/swift-log","last_synced_at":"2025-10-05T17:13:35.287Z","repository":{"id":63905920,"uuid":"372779670","full_name":"binaryscraping/swift-log","owner":"binaryscraping","description":"Simple logging for simples needs.","archived":false,"fork":false,"pushed_at":"2022-05-30T09:39:54.000Z","size":67,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-17T11:51:13.055Z","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/binaryscraping.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}},"created_at":"2021-06-01T09:48:34.000Z","updated_at":"2023-01-10T02:13:46.000Z","dependencies_parsed_at":"2022-11-28T19:28:14.675Z","dependency_job_id":null,"html_url":"https://github.com/binaryscraping/swift-log","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/binaryscraping/swift-log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binaryscraping","download_url":"https://codeload.github.com/binaryscraping/swift-log/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-log/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278486308,"owners_count":25994945,"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-10-05T02:00:06.059Z","response_time":54,"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":"2024-11-15T02:19:42.298Z","updated_at":"2025-10-05T17:13:35.257Z","avatar_url":"https://github.com/binaryscraping.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger\n[![Test](https://github.com/binaryscraping/swift-log/actions/workflows/test.yml/badge.svg)](https://github.com/nativedevbr/swift-log/actions/workflows/test.yml)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fnativedevbr%2Fswift-log%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/nativedevbr/swift-log)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fnativedevbr%2Fswift-log%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/nativedevbr/swift-log)\n\nSimple logging for simples needs.\n\n## Getting Started\n\nDeclare your dependency in your `Package.swift` file.\n\n**Attention: This library is not stable and any update can introduce a BREAKING CHANGE.**\n\n```swift\n.package(name: \"Logger\", url: \"https://github.com/binaryscraping/swift-log.git\", from: \"0.1.0\"),\n```\n and add it to your application target.\n \n ```swift\n .target(name: \"BestExampleApp\", dependencies: [\"Logger\"]),\n ```\n\nNow, let's learn how to use it.\n\n```swift\n// Import the logger package.\nimport Logger\n\n// Create a logger instance, the system is a string that identifies this logging instance.\n// It's recommended to use an inverse domain like your bundle identifier.\n// This logging implementation is based on destinations, each destination represent a place where\n// the log messagens will be sent.\nlet logger = Logger(system: \"co.binaryscraping.best-example-app\", destinations: [.console(), .file(url: URL(...)])\n\n// Then, just call the available methods on the logger instance, there is one method for each\n// logging level. [verbose, debug, info, warning and error].\nlogger.info(\"Hello World!\")\n\n// There's support for adding additional context to a log message.\nlogger.error(\"something is not working\", context: [\"user_id\": \"deadbeef\"])\n```\n\nIf you prefer, there's possibility for defining a shared logger instance through `Logger.main`.\n\n```swift\nLogger.main = Logger(system: \"co.binaryscraping.best-example-app\", destinations: [.console(), .file(url: URL(...)])\n```\n\nIf `Logger.main` is used before being initialized the app will crash. \n\n### Destinations\n\nThis package provides three destinations out of the box, the `console`, `file` and `sqlite`.\n\nThe `console` destination sends the log messages to the console and it's `debug` only, so no logs are sent on `release` builds.\n\nThe `file` destination writes logs messages to a local file that the user must provide.\n\nAnd the `sqlite` destination writes logs to a sqlite database, this is the most powerful destination as you can aggregate and query for logs.\n\nBoths destinations accepts a `Formatter` parameter to customize the formatting logic of the message, there's a default implementation.\n\n#### SQLite Destination\n\nThere is a default implementaiton for a SQLite destination that supports filtering log messages.\n\n```swift\n// Initialize a new SQLiteLoggingStore passing the database path.\n// It's important to keep a single instance of a SQLiteLoggingStore through the whole life cycle.\nlet store = try SQLiteLoggingStore(path: \"path/to/db.sqlite\")\n\n// Init a Logger instance by passing the store's destination\nlet logger = Logger(\n  system: \"co.binaryscraping.logger.tests\",\n  destinations: [store.destination]\n)\n\n// Use the logger\nlogger.info(\"info message\")\n\n// And then query the log messages by using method `logs(where:)`.\nlet logs = try store.logs(\n  where: .or(.level(.info), .level(.error)), .file(\"%Tests.swift\"))\n  \n// The above filter is transformed into a SQL `where` clause and stands for:\n// 'Fetch all log messages that has a level error or info and has happened on files that ends with \"Tests.swift\"'.\n// Example: 'WHERE (\"level\" = 2 OR \"level\" = 4) AND (\"file\" LIKE \"%Tests.swift\")'\n```\n\nFor available filters, take a look at the [Filter `enum`](https://github.com/nativedevbr/swift-log/blob/main/Sources/Logger/SQLite/SQLiteLoggingStore.swift#L77).\n\n#### Custom destinations\n\nThis destination approach makes very easy to add new ones, like this example of a destination that sends the log messages to `Crashlytics`.\n\n```swift\nimport FirebaseCrashlytics\n\nextension Logger.Destination {\n  static let crashlytics = Logger.Destination { msg in\n    // You can use the default formatter for generating a string, \n    // or implement your own formatting logic.\n    let string = Logger.Formatter.default.format(msg)\n    Crashlytics.crashlytics().log(string)\n  }\n}\n\n// Then to use the new destination, simply init a logger passing the `crashlytics` destination.\nLogger.main = Logger(system: \"co.binaryscraping.best-example-app\", destinations: [.console(), .crashlytics])\n```\n\n## Contributing\n\nPull requests are welcome.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinaryscraping%2Fswift-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinaryscraping%2Fswift-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinaryscraping%2Fswift-log/lists"}