KMP RealTime Logger is a Kotlin Multiplatform logging library that replicates the functionality of Android's Log library for use in common code across all platforms (Native, JVM, JS, WASM, and Android).
- Supports all major platforms: Native, JVM, JS, WASM, and Android 🌍
- Mimics the Android Log API for familiar usage 🤖
- Configurable log levels 📊
- Platform-specific implementations ⚙️
- Available on Maven Central 📦
- Throwable support in
Log.e()
for detailed error logging including stack traces 🐞 - Development mode setting for controlling logging in production vs development phases 🚼️
- Live log broadcasting to another device on the same local network 🛡️
Add the following dependency to your build.gradle.kts
file:
implementation("io.github.kdroidfilter:kmplog:0.6.0")
KMPLog is available on Maven Central, ensuring easy integration into your projects.
import com.kdroid.kmplog.Log
Log.d("MyTag", "This is a debug message")
Log.i("MyTag", "This is an info message")
Log.e("MyTag", "This is an error message")
Log.e("MyTag", "This is an error message with exception", throwable)
Log.setLogLevel(Log.INFO)
Log.setDevelopmentMode(true)
Logs will only be displayed when development mode is enabled, providing better control over logging during production and development phases.
To enable broadcasting mode, use the following function:
Log.enableBroadcastingMode(ip: String? = null, port: Int = DEFAULT_SERVICE_PORT)
ip
: Optional. Specify the IP address of the client device to receive the logs. If not provided, the library will automatically discover and connect to the client device using mDNS (Multicast DNS) services.port
: Optional. Specify the port to use for broadcasting. By default, it uses theDEFAULT_SERVICE_PORT
.
Example:
Log.enableBroadcastingMode("192.168.1.10", 8080)
This will broadcast logs to the device with IP 192.168.1.10
on port 8080
.
if (Log.isLoggable("MyTag", Log.DEBUG)) {
// Perform debug logging
}
To facilitate real-time log monitoring, we have also developed a client application that listens to the logs broadcasted over the local network.
The client application uses mDNS to discover broadcasting devices automatically and display the logs in real-time. Note that automatic detection using mDNS only works from an Android or JVM application.
- Automatic discovery of broadcasting devices using mDNS 🔍
- Real-time log display with filters for different log levels (DEBUG, INFO, WARN, ERROR) 📊
- Easy setup with minimal configuration required ⚙️
Below are some screenshots demonstrating the functionality of the client application:
- Real-Time Log Monitoring 🛡️
The client application is available for installation on Android, Windows and Linux. Please download it on the release section.
The client application works by creating a WebSocket server on the local network using Ktor. This server listens for incoming connections from devices broadcasting logs. The server is also published as an mDNS (Multicast DNS) service, making it discoverable by other devices on the same local network without requiring manual configuration.
The KMPLog library itself connects to this WebSocket server using Ktor's WebSocket client capabilities. By leveraging Ktor's lightweight and asynchronous nature, the setup remains efficient and allows real-time log streaming with minimal latency. This architecture enables developers to easily monitor application logs during development or debugging sessions across different platforms.
Log.v(tag: String, msg: String)
: Log a VERBOSE message 🗣️Log.d(tag: String, msg: String)
: Log a DEBUG message 🐛Log.i(tag: String, msg: String)
: Log an INFO message ℹ️Log.w(tag: String, msg: String)
: Log a WARN message⚠️ Log.e(tag: String, msg: String, throwable: Throwable?)
: Log an ERROR message, optionally with a throwable for detailed error logging ❌Log.wtf(tag: String, msg: String)
: Log a WTF (What a Terrible Failure) message 😱Log.println(priority: Int, tag: String, msg: String)
: Log a message with custom priority 📝Log.setDevelopmentMode(isDevelopment: Boolean)
: Enable or disable development mode 🚼️Log.setLogLevel(level: Int)
: Set the log level 🔧Log.enableBroadcastingMode(ip: String? = null, port: Int = DEFAULT_SERVICE_PORT)
: Enable broadcasting mode to stream logs to another device on the local network 🛡️
Contributions are welcome! Please feel free to submit a Pull Request. 💡
The desktop version of the client application uses the Jewel theme, which requires the JetBrains JDK to build the application. Please ensure that you have the JetBrains JDK installed and properly configured when building the desktop client.
KMPLog is released under the MIT License. See the LICENSE file for details.