dart-archive / vm_service_client

A Darty client for the VM service protocol
https://pub.dev/packages/vm_service_client
BSD 3-Clause "New" or "Revised" License
12 stars 19 forks source link

Is there a way to log the messages going over-the-wire? #29

Closed DanTup closed 6 years ago

DanTup commented 6 years ago

I'm trying to debug some issues and it'd be useful to see all of the raw JSON messages going back forth to the VM service. I'm looked through the code but can't see any obvious way to do this - is it possible? (if not, is it a reasonable request?)

nex3 commented 6 years ago

You can pass an arbitrary StreamChannel to new VMServiceClient(), which means you can add logging using things like StreamChannel.changeSink() and StreamChannel.changeStream().

DanTup commented 6 years ago

I'll take a look at that; thanks!

DanTup commented 6 years ago

Not sure if this is exactly what you had in mind, but seems to do the job - thanks 👍

final StreamChannel<String> channel = new IOWebSocketChannel.connect(uri)
    .cast<String>()
    .changeStream((Stream<String> stream) => stream.map(debugPrint))
    .changeSink((StreamSink<String> sink) =>
        new StreamController<String>()
          ..stream.listen((String s) => sink.add(debugPrint(s))));
vmService = new VMServiceClient(channel);