Kotlin Android print to console

前端 未结 6 955
难免孤独
难免孤独 2021-02-03 17:54

I need to print some str to console (Android Studio) using Kotlin. I\'ve tried the:

Log.v() 
Log.d() 
Log.i() 
Log.w() 
Log.e() 

methods. But i

6条回答
  •  暖寄归人
    2021-02-03 17:57

    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/

提交回复
热议问题