Abd*_*ؤمن 33 console intellij-idea dart flutter
你好Flutter Devs :)
我是初学者并使用IntelliJ IDEA,我想将数据记录到控制台?
我试过print()和printDebug(),但没有我的数据被显示颤振控制台.
Abd*_*ؤمن 47
如果你在Flutter里面Widget,你可以使用debugPrint,例如,
import 'package:flutter/foundation.dart';
debugPrint('movieTitle: $movieTitle');
Run Code Online (Sandbox Code Playgroud)
否则,你可以使用Dar的log功能
import 'dart:developer';
log('data: $data');
Run Code Online (Sandbox Code Playgroud)
Rah*_*nge 17
来自“飞镖:开发人员”的日志()
它似乎没有像print()或那样的最大长度限制debugPrint()。
因此,当您想记录整个 API 响应时,它会很有帮助。
并且还有助于在 dart 开发工具中显示格式化的日志记录。
import 'dart:developer'; //(auto import will do this even)
//example for api logging
log("${response?.statusCode} : ${response?.request?.path}",
name: "Response", error: response.data);
Run Code Online (Sandbox Code Playgroud)
max*_*max 15
Dart print()函数输出到系统控制台,您可以使用浮动日志(基本上是adb logcat的包装器)查看该控制台。
如果您一次输出太多,则Android有时会丢弃一些日志行。为了避免这种情况,可以使用debugPrint()。
在这里找到:https : //flutter.io/docs/testing/debugging
mik*_*n22 10
明确地说,debugPrint只能在 Flutter 小部件中工作。
或者,我为 Flutter 应用程序创建了一个记录器: https: //github.com/hiteshsahu/Flutter-Logger
\n只需复制AppLog.dart并添加到您的项目并像这样使用它:
例子:
\n输入
\n AppLog.v("-----------------------------");\n AppLog.d("I am Debug Log With Default TAG");\n AppLog.i("I am Info Log With Default TAG");\n AppLog.w("I am Warn Log With Default TAG");\n AppLog.e("I am Error Log With Default TAG");\n AppLog.wtf("I am Failure Log With Default TAG");\n AppLog.v("I am Verbose Log With Default TAG");\n\n //With TAGS\n AppLog.v("-----------------------------");\n AppLog.d("I am Debug Log With Custom TAG", tag: "Awesome Widget");\n AppLog.i("I am Info Log With Custom TAG", tag: "Awesome Widget");\n AppLog.w("I am Warn Log With Custom TAG", tag: "Awesome Widget");\n AppLog.e("I am Error Log With Custom TAG", tag: "Awesome Widget");\n AppLog.wtf("I am Failure Log With Custom TAG", tag: "Awesome Widget");\n AppLog.v("I am Verbose Log With Custom TAG", tag: "Awesome Widget");\n AppLog.v("-----------------------------");\nRun Code Online (Sandbox Code Playgroud)\n输出:
\n\n\nRun Code Online (Sandbox Code Playgroud)\nRestarted application in 347ms.\nFlutterApp: -----------------------------\nDEBUG|FlutterApp: I am Debug Log With Default TAG\nINFO\xe2\x93\x98|FlutterApp: I am Info Log With Default TAG\nWARN\xe2\x9a\xa0\xef\xb8\x8f|FlutterApp: I am Warn Log With Default TAG\nERROR\xe2\x9a\xa0\xef\xb8\x8f|\xef\xb8\x8fFlutterApp: I am Error Log With Default TAG\nWTF\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf|FlutterApp: I am Failure Log With Default TAG\nFlutterApp: I am Verbose Log With Default TAG\nFlutterApp: -----------------------------\nDEBUG|Awesome Widget: I am Debug Log With Custom TAG\nINFO\xe2\x93\x98|Awesome Widget: I am Info Log With Custom TAG\nWARN\xe2\x9a\xa0\xef\xb8\x8f|Awesome Widget: I am Warn Log With Custom TAG\nERROR\xe2\x9a\xa0\xef\xb8\x8f|\xef\xb8\x8fAwesome Widget: I am Error Log With Custom TAG\nWTF\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf|Awesome Widget: I am Failure Log With Custom TAG\nAwesome Widget: I am Verbose Log With Custom TAG\nFlutterApp: -----------------------------\n
您还可以设置日志级别的过滤器
\n\n\nAppLog.setLogLevel(log_priority); // log_priority 以下的日志将被隐藏
\n
优先级始终是:
\n\n\n详细<=log_priority<=失败
\n
\n\n优先级:详细<调试<信息<警告<错误<失败
\n
示例\n隐藏所有信息和调试日志:
\nAppLog.setLogLevel(AppLog.WARN);\nAppLog.v("-----------------------------");\nAppLog.d("Debug Log Will not be Visible");\nAppLog.i("Info Log Will not be Visible");\nAppLog.w("Warn Log Will be Visible");\nAppLog.e("Error Log Will be Visible");\nAppLog.wtf("Failure Log Will be Visible");\nAppLog.v("Verbose Log Will not be Visible");\nAppLog.v("-----------------------------");\nRun Code Online (Sandbox Code Playgroud)\n输出
\n\n\nRun Code Online (Sandbox Code Playgroud)\nWARN\xe2\x9a\xa0\xef\xb8\x8f|FlutterApp: Warn Log Will be Visible\nERROR\xe2\x9a\xa0\xef\xb8\x8f|\xef\xb8\x8fFlutterApp: Error Log Will be Visible\nWTF\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf|FlutterApp: Failure Log Will be Visible\n
请随意使用我的记录器,或者如果您有一些改进的想法,请创建 PR 或让我知道我会改进它。
\n