My Logger library – Kotlin version

Almost in all my projects during the last five years, I used my custom logging library. But Koltin language has come and finally, I wrote it in Kotlin.

How it looks

GitHub: https://github.com/Pulimet/MyLogLibrary

Installation

repositories { jcenter() }
dependencies { implementation 'net.alexandroid.utils:mylogkt:1.9' }
// Kotlin from Kotlin (Optional, to allow isPackageNameVisible = true)
MyLogKt.packageName = packageName
MyLogKt.isLogsShown = BuildConfig.DEBUG // Also optional, default true

How to use:

logD("Empty 1")
logI("Empty 2")
logW("Empty 3")
logE("Empty 4")

logD("Custom tag example 1", "CustomTag1")

logE("Show Exception", t = NullPointerException())

// Other configurations

var packageName = ""
var isLogsShown = true
var isThreadNameVisible = false
var isTimeVisible = true
var isPackageNameVisible = false
var isClassNameVisible = true
var isMethodNameVisible = true

val classNameLength = 15
val packageAndClassNameLength = 35
val methodNameLength = 15
val threadNameLength = 6
val timeFormat = "HH:mm:ss.SSS"

Android Studio additional configurations:

Stage 1 – Remove logcat headers

Usually, logs look like this

First, go to Configure Logcat Header:

Uncheck all options and press OK:

Now your logs look like below:

Stage 2 – Customize logs color scheme

File -> Settings -> Editor -> Colors & Fonts -> Android Logcat 

Stage 3 – Library customization

Default:

MyLogKt.isPackageNameVisible = true
MyLogKt.isTimeVisible = false  // In last version milliseonds are added
MyLogKt.isThreadIdVisible = true

I hope you would like it. Enjoy!


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.