runInspectorApp function
使用检查器 Zone 运行应用 / Run app with inspector Zone
通过 ZoneSpecification 捕获所有 print() 调用 / Capture all print() calls via ZoneSpecification
appRunner 应用运行回调 / App runner callback
Implementation
void runInspectorApp(VoidCallback appRunner) {
InspectorLogInterceptor.instance.start();
runZonedGuarded(
appRunner,
(error, stackTrace) {
InspectorLogInterceptor.instance.captureLog(
error.toString(),
LogLevel.error,
);
InspectorLogInterceptor.instance.captureLog(
stackTrace.toString(),
LogLevel.error,
);
},
zoneSpecification: ZoneSpecification(
print: (self, parent, zone, line) {
// 先调用原始的 print 确保日志正常输出到控制台 / Call original print first to ensure normal console output
parent.print(zone, line);
// 识别日志级别并捕获 / Detect log level and capture
final level = InspectorLogInterceptor.instance.detectLogLevel(
line.toString(),
);
InspectorLogInterceptor.instance.captureLog(line.toString(), level);
},
),
);
}