To continuously record logcat output (e.g., for writing to a file or real-time monitoring), use adb.execute with a ChanneledLogcatRequest. This returns a channel that you can consume within a coroutine scope.
Important Note on Parsing: Logcat chunks received from the channel might not be newline (\n) terminated. If you need to process logs line-by-line, you must accumulate the chunks in a buffer first to ensure you have complete lines.
ChanneledLogcatRequest supports similar configuration to the sync request, including since, modes, buffers, pid, lastReboot, and filters.
launch {
val channel = adb.execute(
request = ChanneledLogcatRequest(),
scope = this,
serial = "emulator-5554"
)
val logcatChunk = channel.receive()
// Process logcatChunk (e.g., write to file or buffer)
// Dispose of channel to close the resources
channel.cancel()
}