{"id":17990082,"url":"https://github.com/aakira/napier","last_synced_at":"2025-04-07T23:13:29.949Z","repository":{"id":37466282,"uuid":"169042425","full_name":"AAkira/Napier","owner":"AAkira","description":"Logging library for Kotlin Multiplatform","archived":false,"fork":false,"pushed_at":"2024-07-01T00:40:20.000Z","size":3185,"stargazers_count":871,"open_issues_count":26,"forks_count":38,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T22:25:09.967Z","etag":null,"topics":["kotlin-js","kotlin-library","kotlin-multiplatform","kotlin-native"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AAkira.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-02-04T07:33:16.000Z","updated_at":"2025-03-25T18:04:59.000Z","dependencies_parsed_at":"2023-02-01T18:17:18.927Z","dependency_job_id":"bac80c83-07ed-41d8-89c2-1cd16dee289f","html_url":"https://github.com/AAkira/Napier","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AAkira%2FNapier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AAkira%2FNapier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AAkira%2FNapier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AAkira%2FNapier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AAkira","download_url":"https://codeload.github.com/AAkira/Napier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744335,"owners_count":20988783,"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":["kotlin-js","kotlin-library","kotlin-multiplatform","kotlin-native"],"created_at":"2024-10-29T19:16:39.886Z","updated_at":"2025-04-07T23:13:29.921Z","avatar_url":"https://github.com/AAkira.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo][logo]\n\nNapier is a logger library for Kotlin Multiplatform.  \nIt supports Android, Darwin(iOS, macOS, watchOS, tvOS), JVM, JavaScript.  \nLogs written in common module are displayed on logger viewer of each platform.\n\n## Preview\n\n### Android\n\nformat: `[Class name]$[Method name]: [Your log]`\n\nuses the `android.util.Log`(Logcat)\n\n![preview-android][preview-android]\n\n### Darwin(iOS, macOS, watchOS, tvOS)[Intel/Apple silicon]\n\nformat: `[Date time][Symbol][Log level][Class name].[Method name] - [Your log]`\n\nAdded `[async]` label at the end, if it is called from suspend functions.\n\nuses the `print`\n\n![preview-ios][preview-ios]\n\n### JavaScript\n\nuses the `console.log`\n\n![preview-js][preview-js]\n\n### JVM\n\nuses the `java.util.logging.Logger`\n\n![preview-jvm][preview-jvm]\n\n* common sample code\n\n```kotlin\n\nclass Sample {\n\n    fun hello(): String {\n        Napier.v(\"Hello napier\")\n        Napier.d(\"optional tag\", tag = \"your tag\")\n\n        return \"Hello Napier\"\n    }\n\n    suspend fun suspendHello(): String {\n        Napier.i(\"Hello\")\n\n        delay(3000L)\n\n        Napier.w(\"Napier!\")\n\n        return \"Suspend Hello Napier\"\n    }\n\n    fun handleError() {\n        try {\n            throw Exception(\"throw error\")\n        } catch (e: Exception) {\n            Napier.e(\"Napier Error\", e)\n        }\n    }\n}\n```\n\n## Download\n\n### Repository\n\nYou can download this library from MavenCentral or jCenter repository.\n\n* Maven central\n\nYou can download this from `1.4.1`.  \nPackage name is `io.github.aakira`\n\n```groovy\nrepositories {\n    mavenCentral()\n}\n```\n\n* jCenter\n\nYou can download this until `1.4.1`.  \nPackage name is `com.github.aakira`\n\n```groovy\nrepositories {\n    jCenter()\n}\n```\n\n### Version\n\nSet the version name in your build.gradle\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.aakira/napier/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.aakira/napier)\n\n`def napierVersion = \"[latest version]\"`\n\n### Common\n\nAdd the dependency to your commonMain dependencies\n\n* groovy\n\n```groovy\nsourceSets {\n    commonMain {\n        dependencies {\n            // ...\n            implementation \"io.github.aakira:napier:$napierVersion\"\n        }\n    }\n}\n```\n\n* kts\n\n```kotlin\nsourceSets {\n    val commonMain by getting {\n        dependencies {\n            implementation(\"io.github.aakira:napier:$napierVersion\")\n        }\n    }\n}\n```\n\n## Usage\n\n### How to use\n\n### Common module\n\n```kotlin\n\n// verbose log\nNapier.v(\"Hello napier\")\nNapier.v { \"Hello napier\" }\n\n// you can set a tag for each log\nNapier.d(\"optional tag\", tag = \"your tag\")\nNapier.d(tag = \"your tag\") { \"optional tag\" }\n\ntry {\n    ...\n} catch (e: Exception) {\n    // you can set the throwable\n    Napier.e(\"Napier Error\", e)\n    Napier.e(e) { \"Napier Error\" }\n}\n\n// you can also use top-level function\nlog { \"top-level\" }\nlog(tag = \"your tag\") { \"top-level\" }\n\n```\n\n### Initialize\n\nYou must initialize the Napier in your module.\n\n#### Android\n\n```kotlin\nNapier.base(DebugAntilog())\n```\n\n#### iOS\n\n* Write initialize code in your kotlin mpp project.\n\n```kotlin\nfun debugBuild() {\n    Napier.base(DebugAntilog())\n}\n```\n\n|argument|type|description| |-|-| |coroutinesSuffix|Boolean|Added `[async]` label at the end, if it is called from\nsuspend functions|\n\n* Call initialize code from ios project.\n\n```swift\nNapierProxyKt.debugBuild()\n```\n\n### Clear antilog\n\n```kotlin\nNapier.takeLogarithm()\n```\n\n## Log level\n\n| Platform | Sample       |\n|:---------|:-------------|\n| VERBOSE  | Napier.v()   |\n| DEBUG    | Napier.d()   |\n| INFO     | Napier.i()   |\n| WARNING  | Napier.w()   |\n| ERROR    | Napier.e()   |\n| ASSERT   | Napier.wtf() |\n\n## Run background thread\n\nYou can use this library on the background thread on iOS\nusing [Kotlin.coroutines](https://github.com/Kotlin/kotlinx.coroutines) as native-mt.\n\n* Define scope\n\n```kotlin\ninternal val mainScope = SharedScope(Dispatchers.Main)\n\ninternal val backgroundScope = SharedScope(Dispatchers.Default)\n\ninternal class SharedScope(private val context: CoroutineContext) : CoroutineScope {\n    private val job = Job()\n    private val exceptionHandler = CoroutineExceptionHandler { _, throwable -\u003e\n        println(\"[Coroutine Exception] $throwable\")\n    }\n\n    override val coroutineContext: CoroutineContext\n        get() = context + job + exceptionHandler\n}\n```\n\n* Usage\n\n```kotlin\nbackgroundScope.launch {\n    suspendFunction()\n}\n```\n\n## Advancement\n\nYou can inject custom `Antilog`.  \nSo, you should change Antilogs in debug build or release build.\n\n### Crashlytics\n\nCrashlytics AntiLog samples\n\nSample projects use the Firebase Crashlytics.  \nYou must set authentication files to `android/google-services.json` and `ios/Napier/GoogleService-Info.plist`.\n\nCheck the firebase document. [[Android](https://firebase.google.com/docs/android/setup),\n[iOS](https://firebase.google.com/docs/ios/setup)]\n\n* [Android](https://github.com/AAkira/Napier/blob/master/android/src/main/java/com/github/aakira/napier/sample/CrashlyticsAntilog.kt)\n\nWrite this in your application class.\n\n```kotlin\nif (BuildConfig.DEBUG) {\n    // Debug build\n\n    // disable firebase crashlytics\n    FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false)\n    // init napier\n    Napier.base(DebugAntilog())\n} else {\n    // Others(Release build)\n\n    // enable firebase crashlytics\n    FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)\n    // init napier\n    Napier.base(CrashlyticsAntilog(this))\n}\n```\n\n* [iOS](https://github.com/AAkira/Napier/blob/master/mpp-sample/src/iosMain/kotlin/com/github/aakira/napier/CrashlyticsAntilog.kt)\n\nWrite this in your AppDelegate.\n\n```swift\n#if DEBUG\n// Debug build\n\n// init napier\nNapierProxyKt.debugBuild()\n\n#else\n// Others(Release build)\n\n// init firebase crashlytics\nFirebaseApp.configure()\n\n// init napier\nNapierProxyKt.releaseBuild(antilog: CrashlyticsAntilog(\n    crashlyticsAddLog: { priority, tag, message in\n        Crashlytics.crashlytics().log(\"\\(String(describing: tag)): \\(String(describing: message))\")\n},\n    crashlyticsSendLog: { throwable in\n        Crashlytics.crashlytics().record(error: throwable)\n}))\n#endif\n```\n\n## License\n\n```\nCopyright (C) 2019 A.Akira\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttps://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n## Credit\n\nThis library is inspired by [Timber](https://github.com/JakeWharton/timber).  \nI recommend using it if it supports kotlin multiplatform project.😜\n\nThanks for advice.  \n[@horita-yuya](https://github.com/horita-yuya),\n[@terachanple](https://github.com/terachanple)\n\n[logo]: arts/logo.jpg\n\n[preview-android]: arts/screenshot-android.jpg\n\n[preview-ios]: arts/screenshot-ios.jpg\n\n[preview-js]: arts/screenshot-js.jpg\n\n[preview-jvm]: arts/screenshot-jvm.jpg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakira%2Fnapier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faakira%2Fnapier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakira%2Fnapier/lists"}