Set*_*add 10
用于print()将字符串打印到浏览器的控制台:
import 'dart:html';
main() {
var value = querySelector('input').value;
print('The value of the input is: $value');
}
Run Code Online (Sandbox Code Playgroud)
您将看到打印到开发人员控制台的消息.
log()图书馆import \'dart:developer\'也有。
例子:
\n\nint name = "Something";\nlog("ClassName: successfully initialized: $name");\n\n//output\n[log] ClassName: successfully initialized: Something \nRun Code Online (Sandbox Code Playgroud)\n\n请注意,log和debugPrint取 String 值,而不是像print. 因此,您必须.toString()在末尾添加或与字符串插值一起使用,就像我在上面的示例中使用的那样。
来自文档:
\n\n\n\n\n\n您有两种应用程序日志记录选项。第一个是使用
\n\nstdout和stderr。通常,这是使用print()\n 语句或通过导入和调用and\ndart:io上的方法来完成的。例如:stderrstdout\n\n
stderr.writeln(\'print me\');如果一次输出太多,Android 有时会丢弃一些\n 日志行。为了避免这种情况,请使用
\n\ndebugPrint()Flutter\xe2\x80\x99sfoundation\n 库中的 , 。这是一个包装器应用程序日志记录的另一个选项是使用
\n\ndart:developer\nlog()函数。这允许您在日志记录输出中包含更多的粒度和信息。这里\xe2\x80\x99s 是一个例子:Run Code Online (Sandbox Code Playgroud)\n\nimport \'dart:developer\' as developer;\n\nvoid main() { \n developer.log(\'log me\', name: \'my.app.category\');\n developer.log(\'log me 1\', name: \'my.other.category\');\n developer.log(\'log me 2\', name: \'my.other.category\');\n}\n您还可以将应用程序数据传递给日志调用。约定是在调用中使用 error: 命名参数
\n\nlog(),对要发送的对象进行 JSON 编码,并将编码后的字符串传递给错误参数。Run Code Online (Sandbox Code Playgroud)\n\nimport \'dart:convert\'; import \'dart:developer\' as developer;\n\nvoid main() { \n\n var myCustomObject = ...;\n\n developer.log(\n \'log me\',\n name: \'my.app.category\',\n error: jsonEncode(myCustomObject), \n ); \n}\n如果在 DevTool\xe2\x80\x99s 日志记录视图中查看日志记录输出,则 JSON\n 编码的错误参数将被解释为数据对象,并在该日志条目的详细信息视图中呈现。
\n
如果您来这里是为了Flutter,那么debugPrint您应该使用它。
这是相同的文档文本。
/// Prints a message to the console, which you can access using the "flutter"
/// tool's "logs" command ("flutter logs").
/// By default, this function very crudely attempts to throttle the rate at
/// which messages are sent to avoid data loss on Android. This means that
/// interleaving calls to this function (directly or indirectly via, e.g.,
/// [debugDumpRenderTree] or [debugDumpApp]) and to the Dart [print] method can
/// result in out-of-order messages in the logs.
Run Code Online (Sandbox Code Playgroud)
您可能会受到 SDK 版本限制,因为它仅适用于 2.2 及更高版本。
| 归档时间: |
|
| 查看次数: |
8683 次 |
| 最近记录: |