How to listen to flutter application console output? How to listen to flutter application console output? dart dart

How to listen to flutter application console output?


One possible solution that I can think of is to intercept print() method and then you can get all the values whenever the print() method is called in the current zone.

After intercepting the value, you can save it to a file or so whatever you want to. I don't know if it's the most suitable way to do it.

  void main() {  runZoned(() {    // Ends up printing: "Intercepted: in zone".    runApp(MyApp());  }, zoneSpecification: new ZoneSpecification(      print: (Zone self, ZoneDelegate parent, Zone zone, String line) {    parent.print(zone, "Intercepted: $line");    //save to a file or do whatever you want  }));}