简体   繁体   English

如何从flutter应用程序发送打印日志?

[英]How to send print log from flutter app?

如何获取print控制台日志和屏幕截图,以便我可以将堆栈跟踪发送到服务器?

You can get a screenshot of the FlutterView using native code.您可以使用本机代码获取 FlutterView 的屏幕截图。

  • On Android: Bitmap screenshot = flutterView.getBitmap();在 Android 上: Bitmap screenshot = flutterView.getBitmap();
  • On iOS, see this example from Apple.在 iOS 上,请参阅 Apple 的此示例

See the platform channels documentation on mixing Dart and native code.请参阅有关混合 Dart 和本机代码的平台通道文档。

As for the stack trace, here are some tips from the Flutter Sentry library documentation.至于堆栈跟踪,这里有一些来自Flutter Sentry 库文档的提示。

To get a stack trace from within Flutter, override the onError handler:要从 Flutter 中获取堆栈跟踪,请覆盖onError处理程序:

FlutterError.onError = (FlutterErrorDetails details) async {
  throw details;
};

To create a Zone with an error handler that catches all Dart exceptions, wrap your call to runApp in runZoned :要创建一个带有捕获所有 Dart 异常的错误处理程序的区域,请将您对runApp的调用runApprunZoned 中

runZoned<Future<Null>>(() async {
  runApp(new MyApp());
}, onError: (error, stackTrace) async {
  if (error is FlutterErrorDetails) {
    // use error.exception and error.stack
  } else {
    // use error and stackTrace
  }
});

you can use f_logs package, this has a functionality on export logs to a directory on the phone, it has .db and .txt for the logs, and then you can use flutter_archive package to zip the file, and then use flutter_email_sender to send the zip file that contains the logs your development team.你可以使用 f_logs 包,它有将日志导出到手机目录的功能,它有 .db 和 .txt 的日志,然后你可以使用 flutter_archive 包压缩文件,然后使用 flutter_email_sender 发送zip 文件,其中包含您的开发团队的日志。 It worked for us, hope this will helps.它对我们有用,希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM