import 'dart:developer'; //(auto import will do this even)
//example for api logging
log("${response?.statusCode} : ${response?.request?.path}",
name: "Response", error: response.data);
AppLog.v("-----------------------------");
AppLog.d("I am Debug Log With Default TAG");
AppLog.i("I am Info Log With Default TAG");
AppLog.w("I am Warn Log With Default TAG");
AppLog.e("I am Error Log With Default TAG");
AppLog.wtf("I am Failure Log With Default TAG");
AppLog.v("I am Verbose Log With Default TAG");
//With TAGS
AppLog.v("-----------------------------");
AppLog.d("I am Debug Log With Custom TAG", tag: "Awesome Widget");
AppLog.i("I am Info Log With Custom TAG", tag: "Awesome Widget");
AppLog.w("I am Warn Log With Custom TAG", tag: "Awesome Widget");
AppLog.e("I am Error Log With Custom TAG", tag: "Awesome Widget");
AppLog.wtf("I am Failure Log With Custom TAG", tag: "Awesome Widget");
AppLog.v("I am Verbose Log With Custom TAG", tag: "Awesome Widget");
AppLog.v("-----------------------------");
输出:
Restarted application in 347ms.
FlutterApp: -----------------------------
DEBUG|FlutterApp: I am Debug Log With Default TAG
INFOⓘ|FlutterApp: I am Info Log With Default TAG
WARN⚠️|FlutterApp: I am Warn Log With Default TAG
ERROR⚠️|️FlutterApp: I am Error Log With Default TAG
WTF¯\_(ツ)_/¯|FlutterApp: I am Failure Log With Default TAG
FlutterApp: I am Verbose Log With Default TAG
FlutterApp: -----------------------------
DEBUG|Awesome Widget: I am Debug Log With Custom TAG
INFOⓘ|Awesome Widget: I am Info Log With Custom TAG
WARN⚠️|Awesome Widget: I am Warn Log With Custom TAG
ERROR⚠️|️Awesome Widget: I am Error Log With Custom TAG
WTF¯\_(ツ)_/¯|Awesome Widget: I am Failure Log With Custom TAG
Awesome Widget: I am Verbose Log With Custom TAG
FlutterApp: -----------------------------
AppLog.setLogLevel(AppLog.WARN);
AppLog.v("-----------------------------");
AppLog.d("Debug Log Will not be Visible");
AppLog.i("Info Log Will not be Visible");
AppLog.w("Warn Log Will be Visible");
AppLog.e("Error Log Will be Visible");
AppLog.wtf("Failure Log Will be Visible");
AppLog.v("Verbose Log Will not be Visible");
AppLog.v("-----------------------------");
输出
WARN⚠️|FlutterApp: Warn Log Will be Visible
ERROR⚠️|️FlutterApp: Error Log Will be Visible
WTF¯\_(ツ)_/¯|FlutterApp: Failure Log Will be Visible
9条答案
按热度按时间uplii1fm1#
如果你在Flutter
Widget
中,你可以使用debugPrint
,例如:或者,使用Dart的内置
log()
函数kmpatx3s2#
Dartprint()函数输出到系统控制台,您可以使用flutter日志(基本上是adb logcat的 Package 器)查看它。
如果你一次输出太多,Android有时会丢弃一些日志行。为了避免这种情况,你可以使用debugPrint()。
在此找到:https://flutter.io/docs/testing/debugging
jw5wzhpr3#
从'dart:developer'中调用log()
print()
或debugPrint()
那样的最大长度限制。iq0todco4#
为了清楚起见,
debugPrint
只在Flutter小部件中工作。pkmbmrz75#
或者,我已经创建了一个Flutter应用程序的记录器:https://github.com/hiteshsahu/Flutter-Logger
只需复制**
AppLog.dart
**并添加到您的项目中,然后按如下方式使用:示例:
输入
输出:
您也可以为日志级别设置筛选器
日志优先级;//log_priority以下的日志将被隐藏
优先级始终为:
详细〈=日志优先级〈=失败
优先级:详细〈调试〈信息〈警告〈错误〈失败
示例隐藏所有信息与调试日志:
输出
请随时使用我的记录器,或者如果你有一些改进的想法,请创建公关或让我知道我会改进它。
u3r8eeie6#
我在代码中使用了print(),它在调试控制台中打印。
slhcrj9b7#
您可以使用Logger软件包,它既简单又方便
Checkout from here
jyztefdp8#
“"”将“dart:developer”导入为dev;'''
然后再
设备日志('$var')
njthzxwz9#
我将打印命令替换为
logPrint
在Android Studio中调试
Emulator.EMULATOR
等于“”我将查看日志在生产或测试中,我会将其设置为一个数字