There are a couple of ways.
You can use Log.d("TAG", "message"); for example but first you need to import Log.
import android.util.Log
{...}
Log.d("TAG", "message")
{...}
Source: https://developer.android.com/reference/android/util/Log.html
You can also use kotlin's print and println function.
Example:
{...}
print("message")
println("other message")
{...}
Source: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/
Answer from ronniemagatti on Stack OverflowThere are a couple of ways.
You can use Log.d("TAG", "message"); for example but first you need to import Log.
import android.util.Log
{...}
Log.d("TAG", "message")
{...}
Source: https://developer.android.com/reference/android/util/Log.html
You can also use kotlin's print and println function.
Example:
{...}
print("message")
println("other message")
{...}
Source: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/
I've written some extension functions that make use of reified type parameters in order to avoid dealing with declaring log tags in all project's classes. The basic idea is shown by the following snippet:
inline fun <reified T> T.logi(message: String) = Log.i(T::class.java.simpleName, message)
Basically, you can log something to the logcat with the following invocation (W/O external dependencies):
logi("My log message")
You can find a gist here. The functions declared in the gist are a little more elaborated given that they allow:
- Lazy evaluation of the string to be logged out (if for example the string needs to be generated in some way)
- Logging only when in debug mode by default
- Use a given class name when you need to log from within an anonymous class that has no name
Console logging utility
Why isn't this statement printing?
Kotter (a Kotlin-idiomatic library for writing dynamic console application) hits 1.0!
How can I read a character without having to press enter?
First of all, this is a novice question. I am familiar with the Log.d/e utility to print debugging info from any Kotlin code. But, I am trying to see if there is a way to add a tool, more like a command line utility, that prints all the state information or variables that my application has, for instance, values of variables my class has. For instance, my app is Abc which is running right now, I would like to be able to go to adb shell, run a command that prints all the state information of whatever variable my Abc application's classes hold. This is of course, kind of like, developer utility but I coudn't find anything like this, or couldn't gather the idea.
Note: This would be similar to how , say, dumpsys works, because dumpsys can take multiple arguments and print information about an app and its different details.
Any suggestions ? Thanks