Correct way to log to console using Kotlin and Android?

Answered

I've created a new application in IntelliJ using the Android generator (Kotlin). I'm trying to log to the console using Kotlin's `print` and Java's `Log` class with no success:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        print("Hello, world!")
        Log.d("TAG", "Hello, world!");
        setContent {
            Attestation3Theme {
                // A surface container using the 'background' color from the theme
                Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
                    Greeting("Android")
                }
            }
        }
    }
}

When running the application with Debug, the console does not log either. What is the correct way to log to console? 

0
2 comments

Android apps do not log to console, they log to the OS logging subsystem, and you can use logcat tool window in the IDE or “adb logcat” in the terminal to view the logs.

 

1

Thank you, Serge. 

0

Please sign in to leave a comment.