$ show AAkira/Napier
Napier is a Kotlin Multiplatform logging library that provides a clean, structured API inspired by Timber. The core library (napier module) defines an abstract `Antilog` class for custom log backends, a `DebugAntilog` implementation for each target (Android Logcat, JUL, Darwin print, JS console, Wasm console), and a thread-safe singleton `Napier` object with methods for all log levels. It supports Android, Darwin (iOS, macOS, watchOS, tvOS), JVM, JavaScript, and WasmJs. The repository also contains sample applications (Android, iOS, macOS, watchOS, JVM, JS) demonstrating integration, including Crashlytics and coroutines. The architecture is a simple library with a clear separation of concerns: a common API, platform-specific implementations via expect/actual, and atomic reference utilities for thread safety. This is not a data research repository; it is a pure application/library for logging.
The LLM identified 5 files worth highlighting for reuse:
The abstract base class for custom log backends. Defines `performLog(priority, tag, message, throwable)` and an `isEnabled()` guard, allowing consumers to implement platform-specific or third-party loggers (e.g., Crashlytics, remote logging). This is a clean, isolated abstraction that can be reused as a template for any logging framework's pluggable backend.
A generic atomic reference implementation using Kotlin Multiplatform's expect/actual pattern. Provides thread-safe get/set for mutable state used by the Napier singleton. The actual implementations (JVM, Android, JS, Wasm, Darwin) are minimal and could be extracted as a reusable low-level concurrency utility for any KMP project.
A thread-safe mutable list built on top of AtomicRef, storing a list of `Antilog` instances. Provides atomic add/remove/clear operations with a synchronized copy-on-write pattern. This is a reusable pattern for any KMP project needing a thread-safe collection without platform-specific locks.
The main entry point of the library: a singleton object that maintains a list of `Antilog` instances and exposes convenience methods `v`, `d`, `i`, `w`, `e`, `wtf`, and a top-level `log` function. It handles tag extraction from stack traces and iterates over all registered loggers. While tightly coupled to the library's state management, the pattern of providing a static logging facade with pluggable backends is well-executed and could serve as a reference for similar libraries.
A concrete `DebugAntilog` implementation for Android using `android.util.Log`. It maps Napier's priority levels to Android log levels and handles tag truncation to the 23-character limit. This implementation is a clean example of how to bridge a cross-platform logging API to a platform's native logging system and can be reused as a template for adding new platform backends.