Search code examples
androidunity-game-engineadbandroid-logcat

adb logcat, only display custom log events?


I'm using adb logcat -s Unity to view log output from my Android build. However, I'm getting lots of stuff that I don't always need:

08-10 15:53:25.956 17278 17297 D Unity   : Sensor :        Accelerometer ( 1) ; 0.002394 / 0.00s ; BMI160 accelerometer / Bosch
08-10 15:53:25.960 17278 17297 D Unity   : Choreographer available: Enabling VSYNC timing
08-10 15:53:26.133 17278 17297 I Unity   : Launching UI...
08-10 15:53:26.133 17278 17297 I Unity   : UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
08-10 15:53:26.133 17278 17297 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
08-10 15:53:26.133 17278 17297 I Unity   : UnityEngine.Logger:Log(LogType, Object)
08-10 15:53:26.133 17278 17297 I Unity   : UnityEngine.Debug:Log(Object)

Is there a way to only get messages I intentionally output, ie "Launching UI..." above?

Currently I'm using Debug.Log() to output these messages.


Solution

  • You can prefix every log message you send.

    Debug.Log("<my-prefix> Hello World");
    

    And then, on linux:

    adb logcat | grep '<my-prefix>'
    

    Or on Windows:

    adb logcat | find "<my-prefix>"
    

    You can also make your own log method to automatically prefix your log message.

    EDIT

    Using the -e option of logcat you can get the same behavior:

    adb logcat -e <my-prefix>