{"id":15038819,"url":"https://github.com/yoheimuta/bufferedlogger","last_synced_at":"2025-04-10T00:03:23.013Z","repository":{"id":35142031,"uuid":"142240008","full_name":"yoheimuta/BufferedLogger","owner":"yoheimuta","description":"Tiny but thread-safe logger with a buffering and retrying mechanism for iOS","archived":false,"fork":false,"pushed_at":"2022-07-22T01:53:37.000Z","size":9080,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T00:02:41.144Z","etag":null,"topics":["buffered","buffered-writer","ios","logger","swift","swift-framework","swift-logger","swift4"],"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/yoheimuta.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":"2018-07-25T03:01:49.000Z","updated_at":"2024-06-27T20:42:47.000Z","dependencies_parsed_at":"2022-08-24T14:24:59.448Z","dependency_job_id":null,"html_url":"https://github.com/yoheimuta/BufferedLogger","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2FBufferedLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2FBufferedLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2FBufferedLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2FBufferedLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoheimuta","download_url":"https://codeload.github.com/yoheimuta/BufferedLogger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131321,"owners_count":21052819,"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":["buffered","buffered-writer","ios","logger","swift","swift-framework","swift-logger","swift4"],"created_at":"2024-09-24T20:40:20.545Z","updated_at":"2025-04-10T00:03:22.995Z","avatar_url":"https://github.com/yoheimuta.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BufferedLogger\n\n[![Build Status](https://app.bitrise.io/app/75f1a12b7326ea09/status.svg?token=-Wus-j9Iq8IVKcFB3wLhSg\u0026branch=master)](https://app.bitrise.io/app/75f1a12b7326ea09)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\u003ca href=\"https://swift.org\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Language-Swift5-orange.svg\" alt=\"Language Swift 5\"\u003e\u003c/a\u003e\n[![Version](https://img.shields.io/cocoapods/v/BufferedLogger.svg?style=flat)](http://cocoapods.org/pods/BufferedLogger)\n[![License](https://img.shields.io/cocoapods/l/BufferedLogger.svg?style=flat)](http://cocoapods.org/pods/BufferedLogger)\n\nBufferedLogger is a tiny but thread-safe logger with a buffering and retrying mechanism for iOS.\n\n- Buffer log entries until it's time to output them.\n- Batch multiple log entries to use them at the same time.\n- Retry outputing log entries when some backoff time elapsed after some errors occurred.\n\nYou can use this framework...\n\n- To send a group of log entries to your server.\n- To resend them when some errors like a networking trouble were occured.\n\n## Runtime Requirements\n\n- iOS 9.0 or later\n- Swift5\n\n## Installation\n\n### Carthage\n\n```\ngithub \"yoheimuta/BufferedLogger\"\n```\n\n### CocoaPods\n\n```\npod \"BufferedLogger\"\n```\n\n## Usage\n\nFor details, refer to a [Demo project](https://github.com/yoheimuta/BufferedLogger/tree/master/Demo).\n\n### Define your own Writer\n\nPosted log entries are buffered and emitted as a chunk on a routine schedule.\n\nwrite method is ensured to call serially, which means it is run by a serial queue.\n\n```swift\nclass MyWriter: Writer {\n    func write(_ chunk: Chunk, completion: @escaping (Bool) -\u003e Void) {\n        // You can implement something useful like uploading logs to your server.\n        print(\"chunk is \\(chunk)\")\n\n        chunk.entries.forEach {\n            print(\"entry is \\($0)\")\n        }\n\n        completion(true)\n    }\n}\n```\n\n### Make the logger and post a log\n\nYou have to register your writer to the logger and can post your log with it from any thread.\n\nA call to post method is no blocking.\n\n```swift\nimport BufferedLogger\n\nlogger = BFLogger(writer: MyWriter())\nlogger.post(\"1\".data(using: .utf8)!)\nlogger.post(\"2\".data(using: .utf8)!)\nlogger.post(\"3\".data(using: .utf8)!)\n```\n\nYou can also create your configuration for buffering and emitting mechanism.\n\nIf you omit to define your configuration, default below is used. Each meaning is in a comment.\n\n```swift\n/// Config represents a configuration for buffering and writing logs.\npublic struct Config {\n    /// flushEntryCount is the maximum number of entries per one chunk.\n    /// When the number of entries of buffer reaches this count, it starts to write a chunk.\n    public let flushEntryCount: Int\n\n    /// flushInterval is a interval to write a chunk.\n    public let flushInterval: TimeInterval\n\n    /// retryRule is a rule of retry.\n    public let retryRule: RetryRule\n\n    /// maxEntryCountInStorage is a max count of entry to be saved in the storage.\n    /// When the number of entries in the storage reaches this count, it starts to\n    /// delete the older entries.\n    public let maxEntryCountInStorage: Int\n\n    /// storagePath is a path to the entries.\n    /// When you uses multiple BFLogger, you must set an unique path.\n    public let storagePath: String\n\n    public init(flushEntryCount: Int = 5,\n                flushInterval: TimeInterval = 10,\n                retryRule: RetryRule = DefaultRetryRule(retryLimit: 3),\n                maxEntryCountInStorage: Int = 1000,\n                storagePath: String = defaultStoragePath) {\n        self.flushEntryCount = flushEntryCount\n        self.flushInterval = flushInterval\n        self.retryRule = retryRule\n        self.maxEntryCountInStorage = maxEntryCountInStorage\n        self.storagePath = storagePath\n    }\n\n    /// default is a default configuration.\n    public static let `default` = Config()\n}\n```\n\n# Persistence\n\nBufferedLogger stores the unsent entries in the local storage when the application couldn't send log entries.\n\nBy default, it stores them in local files in the Library/Caches directory.\n\nYou can also define your own custom log entry storage backed by any storage system.\n\nSee the EntryStroage protocol for more details.\n\n# Contributing\n\n- Fork it\n- Create your feature branch: git checkout -b your-new-feature\n- Commit changes: git commit -m 'Add your feature'\n- Push to the branch: git push origin your-new-feature\n- Submit a pull request\n\n# License\n\nThe MIT License (MIT)\n\n# Acknowledgement\n\nThank you to the Puree-Swift: https://github.com/cookpad/Puree-Swift\n\nI inspired by this library for the elaborate design, interface and some implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fbufferedlogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoheimuta%2Fbufferedlogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fbufferedlogger/lists"}