{"id":18444151,"url":"https://github.com/sys1yagi/loco","last_synced_at":"2025-04-07T23:32:45.477Z","repository":{"id":141715682,"uuid":"187145958","full_name":"sys1yagi/loco","owner":"sys1yagi","description":"loco (Log Coroutine) is a logging library using coroutine for Android.","archived":false,"fork":false,"pushed_at":"2019-06-01T11:15:58.000Z","size":212,"stargazers_count":23,"open_issues_count":12,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T02:12:44.773Z","etag":null,"topics":["android","coroutine","kotlin","logging"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/sys1yagi.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":"2019-05-17T04:21:53.000Z","updated_at":"2023-04-03T09:38:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"ffc8062d-7c9c-46d3-848e-2cfae6d0b9d7","html_url":"https://github.com/sys1yagi/loco","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/sys1yagi%2Floco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys1yagi%2Floco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys1yagi%2Floco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sys1yagi%2Floco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sys1yagi","download_url":"https://codeload.github.com/sys1yagi/loco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247749899,"owners_count":20989709,"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":["android","coroutine","kotlin","logging"],"created_at":"2024-11-06T06:51:17.949Z","updated_at":"2025-04-07T23:32:45.470Z","avatar_url":"https://github.com/sys1yagi.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# loco\nloco (Log Coroutine) is a logging library using coroutine for Android.\n\n[![CircleCI](https://circleci.com/gh/sys1yagi/loco.svg?style=svg)](https://circleci.com/gh/sys1yagi/loco) ![kotlin](https://img.shields.io/badge/kotlin-1.3.31-blue.svg) ![coroutine](https://img.shields.io/badge/coroutine-1.2.1-blue.svg) ![license](https://img.shields.io/github/license/sys1yagi/loco.svg?maxAge=2592000)\n\n\u003cimg width=\"1215\" alt=\"archi\" src=\"https://user-images.githubusercontent.com/749051/57979861-0d4a5300-7a5e-11e9-8ce1-4bb5b272ce50.png\"\u003e\n\u003cdiv\u003eIcons made by \u003ca href=\"https://www.flaticon.com/authors/smashicons\" title=\"Smashicons\"\u003eSmashicons\u003c/a\u003e from \u003ca href=\"https://www.flaticon.com/\"  title=\"Flaticon\"\u003ewww.flaticon.com\u003c/a\u003e is licensed by \u003ca href=\"http://creativecommons.org/licenses/by/3.0/\" title=\"Creative Commons BY 3.0\" target=\"_blank\"\u003eCC 3.0 BY\u003c/a\u003e\u003c/div\u003e\n\n# Install\n\nAdd your necessary module.\n\n```groovy\ndependencies {\n  // core\n  implementation 'com.sys1yagi.loco:loco-core:1.1.0'\n  \n  // optional, use Gson to serialize the log, and you can use filters to process the logs.\n  implementation 'com.sys1yagi.loco:loco-smasher-filterable-gson:1.0.0'\n\n  // optional, persist the log using sqlite on android.\n  implementation 'com.sys1yagi.loco:loco-store-android-sqlite:1.0.0'\n}\n```\n\n# How to use\n\nLoco has several modules such as log collection and sending, schduler and more.\nEach module is provided by interface and can be implemented as you want.\n\nYou can implement all modules like below:\n\n```kotlin\nfun startLoco() {\n  Loco.start(\n    LocoConfig(\n      store = InMemoryStore(), // persistent layer for buffering logs.\n      smasher = GsonSmasher(Gson()), // serializer for logs.\n      senders = mapOf(\n        // log senders and mapping\n        StdOutSender() to listOf(\n          ClickLog::class\n        )\n      ),\n      scheduler = IntervalSendingScheduler(5000L) // sending interval scheduler\n    )\n  )\n\n  // send logs anytime, anywhere\n  Loco.send(\n    ClickLog(1, \"jack\")\n  )\n}\n\ndata class ClickLog(\n  val id: Int,\n  val name: String\n) : LocoLog\n\nclass GsonSmasher(val gson: Gson) : Smasher {\n  override fun smash(log: LocoLog): String {\n    return gson.toJson(log)\n  }\n}\n\nclass IntervalSendingScheduler(val interval: Long) : SendingScheduler {\n  override suspend fun schedule(\n    latestResults: List\u003cPair\u003cSender, SendingResult\u003e\u003e,\n    config: LocoConfig,\n    offer: () -\u003e Unit\n  ) {\n    delay(interval)\n    offer()\n  }\n}\n\nclass StdOutSender : Sender {\n  override suspend fun send(logs: List\u003cSmashedLog\u003e): SendingResult {\n    logs.forEach {\n      println(it.toString())\n    }\n    return SendingResult.SUCCESS\n  }\n}\n\nclass InMemoryStore : Store {\n  val storage = mutableListOf\u003cSmashedLog\u003e()\n  override suspend fun store(log: SmashedLog) {\n    storage.add(log)\n  }\n\n  override suspend fun load(size: Int): List\u003cSmashedLog\u003e {\n    return storage.take(size)\n  }\n\n  override suspend fun delete(logs: List\u003cSmashedLog\u003e) {\n    storage.removeAll(logs)\n  }\n}\n```\n\n# How to use for Android\n\nThere are some useful modules for Android.\n\n```groovy\ndependencies {\n  // core\n  implementation 'com.sys1yagi.loco:loco-core:1.1.0'\n  \n  // use Gson to serialize the log, and you can use filters to process the logs.\n  implementation 'com.sys1yagi.loco:loco-smasher-filterable-gson:1.0.0'\n\n  // persist the log using sqlite on android.\n  implementation 'com.sys1yagi.loco:loco-store-android-sqlite:1.0.0'\n}\n```\n\nAll you have to do is prepare sender and scheduler, and add mappings.\n\n```kotlin\nclass SampleApplication : Application() {\n  override fun onCreate() {\n    Loco.start(\n      LocoConfig(\n        store = LocoAndroidSqliteStore(), // loco-store-android-sqlite\n        smasher = FilterableGsonSmasher(Gson()), // loco-smasher-filterable-gson\n        senders = // ...\n        scheduler = // ...\n      )\n    )\n  }\n}\n```\n\nSee more [sample](https://github.com/sys1yagi/loco/tree/master/sample)\n\n## Multi Sender\n\nYou can configure multiple Senders.\n\n```kotlin\nLoco.start(\n  LocoConfig(\n    store = // ..., \n    smasher = // ..., \n    senders = mapOf(\n      NetworkSender() to listOf(\n        ClickLog::class,\n        ScreenLog::class\n      ),\n      LogcatSender() to listOf(\n        ScreenLog::class\n      )\n    ),\n    scheduler = // ..., \n  )\n)\n```\n\n# Classes\n\n## LocoLog\n\nIt is marker interface. Logs passed to Loco must implement LocoLog.\n\n```kotlin\ndata class ClickLog(\n  val id: Int,\n  val name: String\n) : LocoLog\n```\n\n\n```kotlin\nLoco.send(\n  ClickLog(2, \"jill\") // OK\n)\n```\n\n## Smasher\n\nit serializes Log.\n\n```kotlin\ninterface Smasher {\n  fun smash(log: LocoLog): String\n}\n```\n\nThe serialized log is set to SmashedLog and passed to the store.\n\n## SmashedLog\n\nSmashedLog has a serialized log and type names.\n\n## Store\n\nStore is responsible for persisting, reading and deleting SmashedLog.\n\n```kotlin\ninterface Store {\n  suspend fun store(log: SmashedLog)\n  suspend fun load(size: Int): List\u003cSmashedLog\u003e\n  suspend fun delete(logs: List\u003cSmashedLog\u003e)\n}\n```\n\n```kotlin\nclass InMemoryStore : Store {\n  val storage = mutableListOf\u003cSmashedLog\u003e()\n  override suspend fun store(log: SmashedLog) {\n    storage.add(log)\n  }\n\n  override suspend fun load(size: Int): List\u003cSmashedLog\u003e {\n    return storage.take(size)\n  }\n\n  override suspend fun delete(logs: List\u003cSmashedLog\u003e) {\n    storage.removeAll(logs)\n  }\n}\n```\n## Sender\n\nSending `List\u003cSmashedLog\u003e` anywhare.\n\n```kotlin\ninterface Sender {\n    suspend fun send(logs: List\u003cSmashedLog\u003e): SendingResult\n}\n```\n\nYou should return `SendingResult`.\n\n```kotlin\nenum class SendingResult {\n  SUCCESS, // consume log record\n  FAILED, // consume log record\n  RETRY // not consume log record\n}\n```\n\n## SendingScheduler\n\nThe SendingScheduler determines the sending interval.\nIt receives the latest sending result and config.\nYou can decide on the next execution plan based on them.\n\n```kotlin\ninterface SendingScheduler {\n  suspend fun schedule(\n    latestResults: List\u003cPair\u003cSender, SendingResult\u003e\u003e,\n    config: LocoConfig,\n    offer: () -\u003e Unit\n  )\n}\n```\n\nThe following is an example of a scheduler that runs at regular intervals.\n\n```kotlin\nclass IntervalSendingScheduler(val interval: Long) : SendingScheduler {\n  override suspend fun schedule(\n    latestResults: List\u003cPair\u003cSender, SendingResult\u003e\u003e,\n    config: LocoConfig,\n    offer: () -\u003e Unit\n  ) {\n    delay(interval)\n    offer()\n  }\n}\n```\n\n## LocoConfig.Extra\n\nLoco has extra settings for convenient.\n\n```kotlin\ndata class Extra(\n  val defaultSender: Sender? = null,\n  val sendingBulkSize: Int = 10,\n  val internist: Internist? = null\n)\n```\n\n### defaultSender\n\nIf you want to send all the logs in a single Sender, you can use defaultSender.\n\n ```kotlin\n Loco.start(\n   LocoConfig(\n     store = //... ,\n     smasher = //... ,\n     senders = mapOf(),\n     scheduler = //... ,\n     extra = LocoConfig.Extra(\n       defaultSender = LocatSender()\n     )\n   )\n )\n ```\n\n### sendingBulkSize\n\nYou can set the number of logs when sending. The default is 10. This value is passed to Store#load(size: Int).\n\n__NOTE: This value is deprecated in 1.2.0.__\n\n\n### Internist\n\nWhat's happening in Loco?\nYou can make an internist intrude.\nInternist can receive inner event of Loco.\n\n```kotlin\nLoco.start(\n  LocoConfig(\n    store = //... ,\n    smasher = //... ,\n    senders = //... ,\n    scheduler = //... ,\n    LocoConfig.Extra(\n      internist = object : Internist {\n        override fun onSend(locoLog: LocoLog, config: LocoConfig) {\n          println(\"onSend\")\n        }\n\n        override fun onStore(log: SmashedLog, config: LocoConfig) {\n          println(\"onStore\")\n        }\n\n        override fun onStartSending() {\n          println(\"onStartSending\")\n        }\n\n        override fun onSending(sender: Sender, logs: List\u003cSmashedLog\u003e, config: LocoConfig) {\n          println(\"onSending: $sender, ${logs.size}\")\n        }\n\n        override fun onEndSending(sendingResults: List\u003cPair\u003cSender, SendingResult\u003e\u003e, config: LocoConfig) {\n          println(\"onStartSending\")\n        }\n      }\n    )\n  )\n)\n```\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2019 Toshihiro Yagi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsys1yagi%2Floco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsys1yagi%2Floco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsys1yagi%2Floco/lists"}