{"id":22989155,"url":"https://github.com/cookpad/puree-swift","last_synced_at":"2025-04-09T08:02:55.192Z","repository":{"id":48173987,"uuid":"120869522","full_name":"cookpad/Puree-Swift","owner":"cookpad","description":"🍯 Awesome log aggregator for iOS","archived":false,"fork":false,"pushed_at":"2024-10-04T11:19:32.000Z","size":294,"stargazers_count":218,"open_issues_count":1,"forks_count":26,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-02T06:09:24.038Z","etag":null,"topics":[],"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/cookpad.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}},"created_at":"2018-02-09T06:58:17.000Z","updated_at":"2025-03-13T03:46:49.000Z","dependencies_parsed_at":"2024-12-29T06:06:04.605Z","dependency_job_id":"3fec9bb1-4fbe-42e4-8670-b218c45703c9","html_url":"https://github.com/cookpad/Puree-Swift","commit_stats":{"total_commits":99,"total_committers":13,"mean_commits":7.615384615384615,"dds":0.7676767676767677,"last_synced_commit":"e510e757e9203eb7c6750374cd76ef295f7f7e41"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2FPuree-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2FPuree-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2FPuree-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2FPuree-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cookpad","download_url":"https://codeload.github.com/cookpad/Puree-Swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"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","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":[],"created_at":"2024-12-15T04:16:36.581Z","updated_at":"2025-04-09T08:02:55.170Z","avatar_url":"https://github.com/cookpad.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Puree\n\n![](Documentation/logo.png)\n\n[![Build Status](https://github.com/cookpad/Puree-Swift/workflows/Puree/badge.svg)](https://github.com/cookpad/Puree-Swift/actions)\n[![Language](https://img.shields.io/badge/language-Swift%205.0-orange.svg)](https://swift.org)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) \n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Puree.svg)](http://cocoadocs.org/docsets/Puree)\n[![Platform](https://img.shields.io/cocoapods/p/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)\n[![License](https://cocoapod-badges.herokuapp.com/l/Puree/badge.svg)](https://github.com/cookpad/Puree-Swift/blob/master/LICENSE)\n\n## Description\n\nPuree is a log aggregator which provides the following features.\n\n- Filtering: Log entries can be processed before being sent. You can add common parameters, do random sampling, ...\n- Buffering: Log entries are stored in a buffer until it's time to send them.\n- Batching: Multiple log entries are grouped and sent in one request.\n- Retrying: Automatically retry to send after some backoff time if a transmission error occurred.\n\n![](./Documentation/overview.png)\n\nPuree helps you unify your logging infrastructure.\n\nCurrently in development so the interface might change.\n\n## Installation\n\n### Carthage\n\n```\ngithub \"cookpad/Puree-Swift\"\n```\n\n### CocoaPods\n\n```ruby\nuse_frameworks!\n\npod 'Puree', '~\u003e 5.0'\n```\n\n### Swift PM\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but Puree-Swift does support its use on supported platforms.\n\nOnce you have your Swift package set up, adding Puree-Swift as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n```swift\ndependencies: [\n    .package(url: \"https://github.com/cookpad/Puree-Swift.git\", .upToNextMinor(from: \"5.3.0\"))\n]\n```\n\n## Usage\n\n### Define your own Filter/Output\n\n#### Filter\n\nA `Filter` should convert any objects into `LogEntry`.\n\n```swift\nimport Foundation\nimport Puree\n\nstruct PVLogFilter: Filter {\n    let tagPattern: TagPattern\n\n    init(tagPattern: TagPattern) {\n        self.tagPattern = tagPattern\n    }\n\n    func convertToLogs(_ payload: [String: Any]?, tag: String, captured: String?, logger: Logger) -\u003e Set\u003cLogEntry\u003e {\n        let currentDate = logger.currentDate\n\n        let userData: Data?\n        if let payload = payload {\n            userData = try! JSONSerialization.data(withJSONObject: payload)\n        } else {\n            userData = nil\n        }\n        let log = LogEntry(tag: tag,\n                           date: currentDate,\n                           userData: userData)\n        return [log]\n    }\n}\n```\n\n#### Output\n\nAn `Output` should emit log entries to wherever they need.\n\nThe following `ConsoleOutput` will output logs to the standard output.\n\n```swift\nclass ConsoleOutput: Output {\n    let tagPattern: TagPattern\n\n    required init(logStore: LogStore, tagPattern: TagPattern) {\n        self.tagPattern = tagPattern\n    }\n\n    func emit(log: LogEntry) {\n        if let userData = log.userData {\n            let jsonObject = try! JSONSerialization.jsonObject(with: userData)\n            print(jsonObject)\n        }\n    }\n}\n```\n\n##### BufferedOutput\n\nIf you use `BufferedOutput` instead of raw `Output`, log entries are buffered and emitted on a routine schedule.\n\n```swift\nclass LogServerOutput: BufferedOutput {\n    override func write(_ chunk: BufferedOutput.Chunk, completion: @escaping (Bool) -\u003e Void) {\n        let payload = chunk.logs.flatMap { log in\n            if let userData = log.userData {\n                return try? JSONSerialization.jsonObject(with: userData, options: [])\n            }\n            return nil\n        }\n        if let data = try? JSONSerialization.data(withJSONObject: payload, options: []) {\n            let task = URLSession.shared.uploadTask(with: request, from: data)\n            task.resume()\n        }\n    }\n}\n```\n\n### Make logger and post log\n\nAfter implementing filters and outputs, you can configure the routing with `Logger.Configuration`.\n\n```swift\nimport Puree\n\nlet configuration = Logger.Configuration(filterSettings: [\n                                             FilterSetting {\n                                                 PVLogFilter(tagPattern: TagPattern(string: \"pv.**\")!)\n                                             }\n                                         ],\n                                         outputSettings: [\n                                             OutputSetting {\n                                                 PVLogOutput(logStore: $0, tagPattern: TagPattern(string: \"activity.**\")!)\n                                             },\n                                             OutputSetting {\n                                                 ConsoleOutput(logStore: $0, tagPattern: TagPattern(string: \"pv.**\")!)\n                                             },\n                                             OutputSetting {\n                                                 LogServerOutput(logStore: $0, tagPattern: TagPattern(string: \"pv.**\")!)\n                                             },\n                                         ])\nlet logger = try! Logger(configuration: configuration)\nlogger.postLog([\"page_name\": \"top\", \"user_id\": 100], tag: \"pv.top\")\n```\n\nUsing this configuration, the expected result is as follows:\n\n|tag name              |-\u003e [ Filter Plugin ] |-\u003e [ Output Plugin ] |\n|----------------------|---------------------|---------------------|\n|pv.recipe.list        |-\u003e [ `PVLogFilter` ] |-\u003e [ `ConsoleOutput` ], [ `LogServerOutput` ]|\n|pv.recipe.detail      |-\u003e [ `PVLogFilter` ] |-\u003e [ `ConsoleOutput` ], [ `LogServerOutput` ]|\n|activity.recipe.tap   |-\u003e ( no filter )     |-\u003e [ `ConsoleOutput` ] |\n|event.special         |-\u003e ( no filter )     |-\u003e ( no output ) |\n\n\nWe recommend suspending loggers while the application is in the background.\n\n```swift\nclass AppDelegate: UIApplicationDelegate {\n    func applicationDidEnterBackground(_ application: UIApplication) {\n        logger.suspend()\n    }\n\n    func applicationWillEnterForeground(_ application: UIApplication) {\n        logger.resume()\n    }\n}\n```\n\n## Tag system\n\n### Tag\n\nA tag is consisted of multiple term delimited by `.`.\nFor example `activity.recipe.view`, `pv.recipe_detail`.\nYou can choose your tags logged freely.\n\n### Pattern\n\n`Filter`, `Output` and `BufferedOutput` plugins are applied to log entries with a matching tag.\nYou can specify tag pattern for plugin reaction rules.\n\n#### Simple pattern\n\nPattern `aaa.bbb` matches tag `aaa.bbb`, doesn't match tag `aaa.ccc` (Perfect matching).\n\n#### Wildcard\n\nPattern `aaa.*` matches tags `aaa.bbb` and `aaa.ccc`, but not `aaa` or `aaa.bbb.ccc` (single term).\n\nPattern `aaa.**` matches tags `aaa`, `aaa.bbb` and `aaa.bbb.ccc`, but not `xxx.yyy.zzz` (zero or more terms).\n\n## Log Store\n\nIn the case an application couldn't send log entries (e.g. network connection unavailable), Puree stores the unsent entries.\n\nBy default, Puree stores them in local files in the `Library/Caches` directory.\n\nYou can also define your own custom log store backed by any storage (e.g. Core Data, Realm, YapDatabase, etc.).\n\nSee the `LogStore` protocol for more details.\n\n## License \n\nPlease do read the [License](https://github.com/cookpad/Puree-Swift/blob/master/LICENSE) before contributing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcookpad%2Fpuree-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcookpad%2Fpuree-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcookpad%2Fpuree-swift/lists"}