log function
void
log(
- dynamic msg
Implementation
void log(dynamic msg) {
if (!kDebugMode) {
debugPrint('$msg');
return;
}
final now = DateTime.now().toString();
final time = now.substring(5, now.length > 23 ? 23 : now.length);
String loc = '';
try {
final lines = StackTrace.current.toString().split('\n');
for (var line in lines) {
// 增加排除 package:ghini 自身,确保定位到外部调用者
if (line.contains('kit.dart') ||
line.contains('package:ghini/') ||
line.contains('package:flutter/') ||
line.trim().isEmpty) {
continue;
}
final m = RegExp(r'\(file:///(.+?)\)').firstMatch(line);
if (m != null) {
loc = ' ${m.group(1)}:';
break;
}
}
} catch (_) {}
debugPrint('\x1B[90m[$time]\x1B[0m\x1B[34m$loc\x1B[0m $msg');
}