【问题标题】:How to listen to flutter application console output?如何收听颤振应用程序控制台输出?
【发布时间】:2021-02-11 16:13:09
【问题描述】:

我在 Flutter 应用程序中添加了不同的库。我在应用程序中实现了一项功能,每当从任何库或错误消息将错误或消息打印到控制台时,我都想将该错误或消息字符串发送到服务器。

如何以编程方式在颤振中收听控制台,以便每当将字符串打印到控制台时,我都可以捕获它以稍后将其发送到服务器?

【问题讨论】:

    标签: flutter dart logging


    【解决方案1】:

    我能想到的一种可能的解决方案是拦截print()方法,然后只要在当前区域中调用print()方法,就可以获取所有值。

    截取值后,您可以将其保存到文件或任何您想要的文件中。我不知道这是否是最合适的方式。

      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
      }));
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-08
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 2013-03-03
      • 2019-09-10
      • 1970-01-01
      相关资源
      最近更新 更多