A simple, lightweight, strait to the point logging library for Kotlin Multiplatform Mobile.
Out of the box, the library provides platform-specific loggers for Logcat, NSLog and OSLog, but its easy to extend and configure more.
Two easy steps:
- Install any
Appenderyou want on your application. - Call
LOG's methods everywhere throughout your app.
LOG.i("MyTag", "Hello World")You can control what will be logged based on severity.
For example, if you only want an Appender to receive logs WARN and up, you can configure it by setting the minLogLevel of the Appender.
Lodge is published to GitHub Packages, which requires authentication even for public packages. Use a personal access token with the read:packages scope.
repositories {
maven {
url = uri("https://maven.pkg.github.com/Mindera/Lodge")
credentials {
username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
}
}
}commonMain {
dependencies {
implementation("com.mindera.lodge:Lodge:1.0.0")
}
}For evaluation only. The XCFramework exists so that any team curious about Kotlin Multiplatform can try a real KMP artifact in an iOS app. It isn't a supported product: its API can change between releases and it comes with no compatibility guarantees.
Add it with Swift Package Manager, either in Xcode with File > Add Package Dependencies or in your Package.swift:
dependencies: [
.package(url: "https://github.com/Mindera/Lodge.git", from: "1.0.0")
]No authentication is needed. It needs iOS 12.0 or later, and the framework is static.
Only release tags can be used, not main: KMMBridge generates Package.swift for each release and commits it to that tag only. The binary is attached to the GitHub release, so it never enters the repository.
Then use it from Swift:
import Lodge
LOG.shared.add(appender: OSAppender())
LOG.shared.i(tag: "MyTag", text: "Hello World")
LOG.shared.d(tag: "MyTag", message: { "Built only when an appender accepts it" })Before you try it:
- Logs are written asynchronously. Anything still queued when the process exits is lost, which can affect unit tests and short-lived extensions. Call
try await LOG.shared.flush()before the process ends to wait for them. - It includes its own Kotlin runtime. If your app already uses a KMP framework, add Lodge to that shared module rather than using this XCFramework.
The module applies a single neutral build convention, com.mindera.lodge.build, which owns toolchains, platform targets, Android configuration and publishing. The module script keeps dependencies, source sets and the library identity (com.mindera.lodge).
The owning build decides which implementation provides that plugin:
- Standalone:
settings.gradle.ktsincludesbuild-logic, which ships the default implementation. Run./gradlew buildhere. - Embedded: a host build (for example as a Gradle subproject) supplies its own implementation through its
pluginManagement. Lodge'sbuild-logicis not included, so exactly one implementation is resolved.
- Bump
LIBRARY_VERSIONingradle.properties, because GitHub Packages rejects a version that already exists. - Run the Publish workflow from the Actions tab on
main.
The workflow publishes to GitHub Packages, creates the GitHub release, attaches the XCFramework, and tags a commit containing the generated Package.swift. Don't create the tag or the release by hand.
Publishing is part of the standalone convention in build-logic, so an embedding build doesn't inherit it.
Copyright (c) 2022 Mindera - Software Craft
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.