Log.e with Kotlin

Viewed 48490

As we have used Log.e() for logging error with java code. I was looking for same functionality with Kotlin. Though i have found Logger class

val Log = Logger.getLogger(MainActivity::class.java.name)
Log.warning("Hello World")

It is showing log in android studio logcat.

But does there any way to print log in red color the same way Log.e() does?

4 Answers

As Kotlin guarantee 100% interoperable with Java and Android, you can use Log or any java class in kotlin also.

If you insist to use Logger class, you can get the same output as Log#e using Logger#severe

Anyway, I recommend to use Timber or similar. There are many avantages on using it and using. Android's Log class logs all your outputs in any enviroment, and also consumes machine resources that you should get rid in production.

Related