Reputation: 35549
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?
Upvotes: 27
Views: 68185
Reputation: 9398
Log.e()
will work perfectly in Kotlin.
In Kotlin, we also have a Logger class to log something.
Logger.getLogger(Test::class.java.name).warning("Hello..")
Otherwise, you have to use some other library like: kotlin-logging, anko logging etc.
Upvotes: 16
Reputation: 9263
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.
Upvotes: 4
Reputation: 4374
You can use all your java classes from Kotlin, so Log.e( )
in java is exactly the same as Log.e( )
in Kotlin.
If you want extra capabilities like automatically infering the tag string, you can use something like AnkoLogger
Upvotes: 3