app/lib/common/utils/log.dart

27 lines
458 B
Dart
Raw Normal View History

2024-03-01 20:59:43 +08:00
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:synchronized/synchronized.dart';
var _logLock = Lock();
2024-03-07 23:01:32 +08:00
File? _logFile;
2024-03-01 20:59:43 +08:00
void dPrint(src) async {
if (kDebugMode) {
print(src);
}
try {
await _logLock.synchronized(() async {
2024-03-07 23:01:32 +08:00
_logFile?.writeAsString("$src\n", mode: FileMode.append);
2024-03-01 20:59:43 +08:00
});
} catch (_) {}
}
2024-03-07 23:01:32 +08:00
void setDPrintFile(File file) {
_logFile = file;
}
2024-03-10 19:44:53 +08:00
File? getDPrintFile() {
return _logFile;
}