Search code examples
androidadb

Can we add Debug information to Logcat using ADB commands or any other means?


I am running a script on an Android device and getting data from logcat. Is there anyway I can add debug statements to logcat in runtime using adb commands or any other means?


Solution

  • By default Android should redirect stdout and stderr to /dev/null. You can for instance change this behaviour by redirect stdout/stderr to log with:

    $ adb shell stop
    $ adb shell setprop log.redirect-stdio true
    $ adb shell start
    

    more info here: https://developer.android.com/studio/command-line/logcat.html#viewingStd

    Update: From within your script, just use:

    log -p i "your message"
    

    to append the message to the log