### Build and run JVM sample Source: https://github.com/aakira/napier/blob/master/jvm/README.md Builds the JVM sample with Gradle and runs the resulting JAR file. ```sh ./gradlew :jvm:build java -jar jvm/build/libs/jvm.jar ``` -------------------------------- ### Gradle dependencies for JVM sample Source: https://github.com/aakira/napier/blob/master/jvm/README.md Specifies the project dependencies for the JVM sample. Used as part of the workaround for the known issue. ```groovy compile project(":napier") compile project(":mpp-sample") ``` -------------------------------- ### Common sample code for Napier logging Source: https://github.com/aakira/napier/blob/master/README.md Common sample code showing Napier logging calls: verbose, debug with tag, info, warning, and error with exception. Demonstrates usage in regular and suspend functions. ```kotlin class Sample { fun hello(): String { Napier.v("Hello napier") Napier.d("optional tag", tag = "your tag") return "Hello Napier" } suspend fun suspendHello(): String { Napier.i("Hello") delay(3000L) Napier.w("Napier!") return "Suspend Hello Napier" } fun handleError() { try { throw Exception("throw error") } catch (e: Exception) { Napier.e("Napier Error", e) } } } ``` -------------------------------- ### Initialize Napier on Android Source: https://github.com/aakira/napier/blob/master/README.md Initializes Napier on Android by setting the base antilog to DebugAntilog. ```kotlin Napier.base(DebugAntilog()) ``` -------------------------------- ### Add jCenter repository for Napier Source: https://github.com/aakira/napier/blob/master/README.md Add jCenter repository to your build.gradle to download Napier until version 1.4.1. Package name is com.github.aakira. ```groovy repositories { jCenter() } ``` -------------------------------- ### Initialize Napier for iOS (Kotlin MPP) Source: https://github.com/aakira/napier/blob/master/README.md Defines a debugBuild function in the Kotlin MPP project to initialize Napier with DebugAntilog for iOS. ```kotlin fun debugBuild() { Napier.base(DebugAntilog()) } ``` -------------------------------- ### Call Napier initialization from iOS Source: https://github.com/aakira/napier/blob/master/README.md Calls the Kotlin-generated debugBuild() from the iOS project to initialize Napier. ```swift NapierProxyKt.debugBuild() ``` -------------------------------- ### Add Maven Central repository for Napier Source: https://github.com/aakira/napier/blob/master/README.md Add Maven Central repository to your build.gradle to download Napier from version 1.4.1. Package name is io.github.aakira. ```groovy repositories { mavenCentral() } ``` -------------------------------- ### Napier common logging usage Source: https://github.com/aakira/napier/blob/master/README.md Shows the common Napier logging API: verbose, debug, error with throwable, and top-level log functions. Supports tag and lambda variants. ```kotlin // verbose log Napier.v("Hello napier") Napier.v { "Hello napier" } // you can set a tag for each log Napier.d("optional tag", tag = "your tag") Napier.d(tag = "your tag") { "optional tag" } try { ... } catch (e: Exception) { // you can set the throwable Napier.e("Napier Error", e) Napier.e(e) { "Napier Error" } } // you can also use top-level function log { "top-level" } log(tag = "your tag") { "top-level" } ``` -------------------------------- ### Configure Napier with Crashlytics in iOS (Swift) Source: https://github.com/aakira/napier/blob/master/README.md Configure Napier with Firebase Crashlytics in an iOS AppDelegate. In debug builds, initialize Napier with debugBuild(); in release builds, configure Firebase and use releaseBuild with a CrashlyticsAntilog that logs messages and records errors. Requires GoogleService-Info.plist and the CrashlyticsAntilog class from the sample project. ```swift #if DEBUG // Debug build // init napier NapierProxyKt.debugBuild() #else // Others(Release build) // init firebase crashlytics FirebaseApp.configure() // init napier NapierProxyKt.releaseBuild(antilog: CrashlyticsAntilog( crashlyticsAddLog: { priority, tag, message in Crashlytics.crashlytics().log("\(String(describing: tag)): \(String(describing: message))") }, crashlyticsSendLog: { throwable in Crashlytics.crashlytics().record(error: throwable) })) #endif ``` -------------------------------- ### Run suspend function on background thread Source: https://github.com/aakira/napier/blob/master/README.md Launches a coroutine on the background scope to run suspend functions on a background thread. ```kotlin backgroundScope.launch { suspendFunction() } ``` -------------------------------- ### Clear Napier antilog Source: https://github.com/aakira/napier/blob/master/README.md Clears the current antilog, removing the base antilog. ```kotlin Napier.takeLogarithm() ``` -------------------------------- ### Define coroutine scopes for background thread Source: https://github.com/aakira/napier/blob/master/README.md Defines a SharedScope class for coroutine scopes on main and background dispatchers, with a job and exception handler. ```kotlin internal val mainScope = SharedScope(Dispatchers.Main) internal val backgroundScope = SharedScope(Dispatchers.Default) internal class SharedScope(private val context: CoroutineContext) : CoroutineScope { private val job = Job() private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> println("[Coroutine Exception] $throwable") } override val coroutineContext: CoroutineContext get() = context + job + exceptionHandler } ``` -------------------------------- ### Add Napier dependency with Groovy DSL Source: https://github.com/aakira/napier/blob/master/README.md Add the Napier dependency to commonMain dependencies using Groovy DSL. Requires setting napierVersion to the latest version. ```groovy sourceSets { commonMain { dependencies { // ... implementation "io.github.aakira:napier:$napierVersion" } } } ``` -------------------------------- ### Configure Napier with Crashlytics in Android (Kotlin) Source: https://github.com/aakira/napier/blob/master/README.md Configure Napier with Firebase Crashlytics in an Android application class. In debug builds, disable Crashlytics collection and use DebugAntilog; in release builds, enable collection and use CrashlyticsAntilog. Requires google-services.json and the CrashlyticsAntilog class from the sample project. ```kotlin if (BuildConfig.DEBUG) { // Debug build // disable firebase crashlytics FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false) // init napier Napier.base(DebugAntilog()) } else { // Others(Release build) // enable firebase crashlytics FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true) // init napier Napier.base(CrashlyticsAntilog(this)) } ``` -------------------------------- ### Add Napier dependency with Kotlin DSL Source: https://github.com/aakira/napier/blob/master/README.md Add the Napier dependency to commonMain dependencies using Kotlin DSL (kts). Requires setting napierVersion to the latest version. ```kotlin sourceSets { val commonMain by getting { dependencies { implementation("io.github.aakira:napier:$napierVersion") } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.