Skip to main content

Android: Logging to Logcat

Logging is a useful way to debug and just check what is going on in general.

It took me a minute to figure out how to log a message to Logcat in Android studio


  • The Logcat window in Android Studio displays system messages
  • Make sure you import android.util.Log
  • If you use the TAG convention with the Log class be sure to define the variable 
    • such as  val TAG = "MyMessage" 
  • Then print you message to the log file by using the Log class
package com.example.swipeactivities

import android.os.Bundle
import android.util.Log
import android.widget.Button

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {

        val TAG = "MyMessage"
        Log.i(TAG, "Hello World")