Skip to content
xabarasPublic

About

A simple Kotlin Multiplatform logging library

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

KmpCat

Maven Central Kotlin License


KmpCat is a simple Kotlin Multiplatform logging library, it supports the most common log levels (VERBOSE, INFO, WARNING, DEBUG, ERROR, WTF) and handles error prone cases such as Exceptions with no message.

It works with the following targets:

  • Android
  • iOS
  • Desktop (JVM)
  • Server-side (JVM)
  • Web based on Kotlin/Wasm
  • Web based on Kotlin/JS

Table of contents

How do I get set up?

Get it via Gradle

implementation('it.xabaras.kmp.logging:kmp-cat:1.0.1')

or Maven

<dependency>
	<groupId>it.xabaras.kmp.logging</groupId>
	<artifactId>kmp-cat</artifactId>
	<version>1.0.1</version>
	<type>pom</type>
</dependency>

Usage

KmpCat is simple to use, you just have to call the appropriate log methods from the KmpCat object.

E.g.

KmpCat.i("Hello KmpCat! This is my first log call")

KmpCat.d("This is a debug message")

KmpCat.e("An error has occurred")

KmpCat.e("MySampleApp", exception)

Methods

KmpCat provides logging methods for 6 log levels:

fun v( ... ) // VERBOSE
fun i( ... ) // INFO
fun w( ... ) // WARN
fun d( ... ) // DEBUG
fun e( ... ) // ERROR
fun wtf( ... ) // What a Terribe Failure 😃

Each log level method has five overrides based on the input parameters.

(msg: String)

Takes a message string as a parameter and logs the message Usually it gets called like this:

KmpCat.d("You just pressed the Cancel button.")

(tag: String, msg: String)

Takes a tag and a message string as parameters and logs the message with the given tag Usually it gets called like this:

KmpCat.d("ExampleApp", "You just pressed the Cancel button.")

(tag: String, t: Throwable)

Takes a tag and a Throwable (e.g. Exception) as parameters and logs the Throwable message if any

try {
  // Your code
} catch(e: Exception) {
  KmpCat.e("ExampleApp", e)
}

(o: Any, t: Throwable)

Take a Kotlin object and a Throwable (e.g. Exception) as parameter, use the object's class name as a tag and logs the error message if any

try {
  // Your code
} catch(e: Exception) {
  KmpCat.e(this, e)
}

(o: Any, msg: String)

Takes a Kotlin object and a String as parameters, uses the object's class name as a tag and logs the message

try {
  // Your code
} catch(e: Exception) {
  KmpCat.e(this, "We're sorry! An Exception occurred.")
}

Proguard

You can add the following lines to your app's proguard configuration file to enforce security (avoid adding logging methods to released app):

-assumenosideeffects class it.xabaras.kmp.logging.KmpCat {
    public static void v(...)
    public static void i(...)
    public static void d(...)
    public static void w(...)
    public static void e(...)
    public static void wtf(...)
}

About

A simple Kotlin Multiplatform logging library

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages