-
Notifications
You must be signed in to change notification settings - Fork 67
How to stream logcat output line by line ? #88
-
I want to stream logs line by line and close when I got specific line.
Currently, I manually open adb executable, but disadvantage, it kills adbclient.
Dim info As New ProcessStartInfo With { .FileName = AdbPath, 'Path.Combine(AdbPath, "adb.exe"), .Arguments = "-s emulator-5555 shell logcat -s LogInterceptor:V", .UseShellExecute = False, .RedirectStandardOutput = True, .CreateNoWindow = True } Dim P = Process.Start(info) Using reader = P.StandardOutput While Not reader.EndOfStream Dim Line = reader.ReadLine() End While End Using
How can I implement in AdvancedSharpAdbClient instead ?
Something like
Public Function RunAdb(client As AdbClient, device As DeviceData, cmd As String) As String Dim receiver As New ConsoleOutputReceiver() client.ExecuteRemoteCommand(cmd, device, receiver) Dim Out = receiver.ToString() 'receiver.ReadLine ? receiver.Flush() Return Out End Function
Beta Was this translation helpful? Give feedback.
All reactions
It cannot use filter because the filter is not supported on logcat -B. You can filter it by yourself.
Replies: 4 comments 8 replies
-
Beta Was this translation helpful? Give feedback.
All reactions
-
how to stop receiving the logs
Beta Was this translation helpful? Give feedback.
All reactions
-
CancellationToken cancellationToken
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Dim Client = New AdbClient() Dim device = Client.GetDevices().FirstOrDefault() Dim sink = Sub(L As LogEntry) Console.WriteLine(L) End Sub Client.RunLogService(device, sink, LogId.System) Console.ReadLine()
Okay this works, it shows logging. Now two questions:
- Is there way I can change arguments ? e.g
logcat -s LogInterceptor:V - How to stop ?
Beta Was this translation helpful? Give feedback.
All reactions
-
It cannot use filter because the filter is not supported on logcat -B. You can filter it by yourself.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@wherewhere I pasted sample code for future reference.
It suppose to be like that, right ?
Sub WaitForServer() Dim Source As New CancellationTokenSource() Dim Token As CancellationToken = Source.Token Dim sink = Sub(Log As Object) If Log.Tag.ToString() = "LogInterceptor" Then If Log.Message.Contains("Response body") Then Console.WriteLine(Log.Message) Source.Cancel() End If End If End Sub Dim Service = Client.RunLogServiceAsync(Device, sink, Token, LogId.Crash, LogId.Events, LogId.Main, LogId.Radio, LogId.System) Service.Wait() End Function
Thanks so much for the support. Cheers!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Not wait a Task, make async sync may cause thread locked...
In lester version I have add a in bool to notify cancellation in sync version. You can try it from GitHub Package.
Beta Was this translation helpful? Give feedback.
All reactions
-
I see isCancelled bool. Is it replacement to cancellation token, right ?
We use it like this ?
Sub WaitForServer() Dim isCancelled As Boolean = False Dim sink = Sub(Log As Object) If Log.Tag.ToString() = "LogInterceptor" Then If Log.Message.Contains("Response body") Then Console.WriteLine(Log.Message) isCancelled = True End If End If End Sub Client.RunLogService(Device, sink, isCancelled, LogId.Crash, LogId.Events, LogId.Main, LogId.Radio, LogId.System) End Function
Beta Was this translation helpful? Give feedback.
All reactions
-
Is that isCanceled doesn't need in?
Beta Was this translation helpful? Give feedback.
All reactions
-
I didn't tested, as not sure where to download that package ?
But most of times, vb net takes care itself. Like variable Dim VarA As String = 1 will automatically converted to string.
So if I remember correctly, vb net itself reference, when in/ref variable found.
Beta Was this translation helpful? Give feedback.
All reactions
-
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#installing-a-package
It is so difficult to download nuget though GitHub Package. You can directly download the .nuget uploaded in action and use it as local nuget.
Beta Was this translation helpful? Give feedback.
All reactions
-
Now you can using foreach to enumerate the output lines by IEnumerable<string> ExecuteRemoteCommand(string command, DeviceData device, Encoding encoding)
https://github.com/SharpAdb/AdvancedSharpAdbClient/blob/main/AdvancedSharpAdbClient%2FAdbClient.cs#L408-L507
Beta Was this translation helpful? Give feedback.