LogKit

Additional

Language
Kotlin
Version
1.2.0 (Mar 15, 2019)
Created
Aug 2, 2018
Updated
Apr 4, 2019
Owner
Andrea Cioccarelli (AndreaCioccarelli)
Contributor
Andrea Cioccarelli (AndreaCioccarelli)
1
Activity
Badge
Generate
Download
Source code

Promotion

LogKit

LogKit is a very small android library, made to make logging easier, faster and stilish to be incorporated in your code.

Repository

LogKit uses jitpack as package repository. To use it you need to add that line to your project build.gradle file:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

And the dependency to your module build.gradle file:

dependencies {
    implementation 'com.github.AndreaCioccarelli:LogKit:1.2.0'
}

Introduction

LogKit aims to reduce at the minimum the lines of code you need to perform every operation. The default android logging kit provides the class Log, with functions like d(), w(), e(), i().

val X = 107
val Y = null
Log.d("MyTag", "${String.valueOf(X)}, ${if (Y == null) "null" else String.valueOf(Y)}")

Instead, LogKit has condensed functions like logd(), logw(), loge(), logi(). You don't have to pass restricted String values, nor non-null values, classes, lists, enums, and so on and so forth.

val X = 107
val Y = null
logd(X, Y)

Usage

Despite this library is small and simple, it's extremely powerful and it has many potential usages. Let's check them out

Types

This library can log everything you pass to the function without limitations depenting on the type and the nullability state (Useful both for Java and Kotlin developers).

val A = "Pizza"
val B = 18
val C = 0x0002
val D = Throwable("PizzaWithPineAppleException")
val E = 7.5

logd(A)
logd(B)
logd(C)
logd(D)
logd(E)

vararg input

There is a better way to do what we saw in the previous example, obtaining the same exact result.

logd(A, B, C, D, E)

Every function in this library requires a vararg argument of Any type, and so you are allowed you to pass multiple and different types at the same function call.

Data types

One peculiarity of this library is that gives you the ability to log raw, pure data and to check them on the logcat. You can log literally everything that is inside your scope.

val X = listOf("House", "Wilson", "Chase", 13, "Foreman")
logd(X)
LogKit [D]: [House, Wilson, Chase, 13, Foreman]

Nullable types

You can log nullable types. If they are null, the literal "null" is logged, else the non-null value is printed out.

val Y = null
logd(Y)
LogKit [D]: null

Logging code result

You can pass executable code to the function. The functions accepts an argument of type () -> Any?. This is useful to group testing code in one scope

logd {
    val J = 18
    val K = 64
    
    max(J, K)
}
LogKit [D]: 64
logd {
    val prefs = getSharedPreferences("general_settings", Context.MODE_PRIVATE);
    String value = prefs.getString("key", "") // " pizza "
    
    value.trim() 
}
LogKit [D]: pizza