初始化
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// TEMP: 诊断 release-only 问题用,临时让 debugLog 在 release 也输出。
|
||||
// 用完务必改回 false,否则线上日志会被业务 print 淹没。
|
||||
const _kForceDebugLogInRelease = false;
|
||||
|
||||
void debugLog(Object? message, [Object? message2]) {
|
||||
if (!kDebugMode && !_kForceDebugLogInRelease) return;
|
||||
_printChunked(message);
|
||||
if (message2 != null) _printChunked(message2);
|
||||
}
|
||||
|
||||
/// 长文本完整输出:
|
||||
/// 1) 用 debugPrint 替代 print —— dart:core print 高频时会被 Flutter/logcat 节流丢段,
|
||||
/// debugPrint 节流但排队不丢,能保证完整;
|
||||
/// 2) 按 ~800 字符分段 —— 避开 Android logcat 单条(~1KB)截断。
|
||||
void _printChunked(Object? message) {
|
||||
final str = message?.toString() ?? 'null';
|
||||
const chunkSize = 800;
|
||||
if (str.length <= chunkSize) {
|
||||
debugPrint(str);
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < str.length; i += chunkSize) {
|
||||
final end = (i + chunkSize < str.length) ? i + chunkSize : str.length;
|
||||
debugPrint(str.substring(i, end));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user