I have the an Android App on Kotlin that prints many logs many times and I need to create a script on Batch that receives the logs until there is a specific log (e.g. "end_of_logs_specific_log").
I`m printing the logs in my Koltin app this way:
fun logInLogcat(log: String) {
Log.d(TEST_TAG, log)
}
and I need to start the app from the command line and start to read all of the logs with tag "TEST_TAG" until I read the specific log "end_of_logs_specific_log".
Up to now I have the following batch script:
@REM build and install the app
gradlew installDebug
@REM clear the logcat
adb adb logcat -c
@REM start the application with specific data (e.g. "testdata")
adb shell am start -n com.mycompany.myapp/.ExampleActivity -e "testdata"
Now I have to read all of the logs with the tag "TEST_TAG", and I have tryied :
Calling on every 1 second in a while loop:
adb shell logcat -d -s "TEST_TAG" && adb shell logcat -c
This command read the logs with the tag "TEST_TAG" and then delete the logs. This way I will get the new logs every time.
The problem here is that between the first call to adb shell logcat -d -s "TEST_TAG"
and the second call that is adb shell logcat -c
we have one time window where we can dismiss something that is logged in the exact moment.
Calling on every 1 second in a while loop
@REM save the current time on the device
NEW_TIMESTAMP=$(adb shell echo $EPOCHREALTIME)
adb shell logcat -d -s -T $TIMESTAMP "show_unit_tests"
$OLD_TIMESTAMP = $NEW_TIMESTAMP
The idea here is that I will get only the new logs with the timestamp that will be updated on every read of the logs. But the problem is that I can read some of the logs twice
And the question:
Is there a way to read the new logs second my second in the COMMAND LINE on the Desktop with any command without dismissing any log or reading the logs twice?
(e.g. read the logcat with adb shell logcat -d -s "TEST_TAG"
and delete exactly what you have read from the log buffer)