mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
refactor: add back exceptions to file support
This commit is contained in:
parent
f9087b63d5
commit
de61d90938
@ -1,16 +1,23 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
import 'dart:isolate';
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
import 'package:path/path.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:spotube/utils/platform.dart';
|
||||||
|
|
||||||
class AppLogger {
|
class AppLogger {
|
||||||
static late final Logger log;
|
static late final Logger log;
|
||||||
|
static late final File logFile;
|
||||||
|
|
||||||
static initialize(bool verbose) {
|
static initialize(bool verbose) {
|
||||||
log = Logger(
|
log = Logger(
|
||||||
level: kDebugMode || (verbose && kReleaseMode) ? Level.all : Level.info,
|
level: kDebugMode || (verbose && kReleaseMode) ? Level.all : Level.info,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
getLogsPath().then((value) => logFile = value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static R? runZoned<R>(R Function() body) {
|
static R? runZoned<R>(R Function() body) {
|
||||||
@ -43,11 +50,36 @@ class AppLogger {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reportError(
|
static Future<File> getLogsPath() async {
|
||||||
|
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
|
if (kIsAndroid) {
|
||||||
|
dir = (await getExternalStorageDirectory())?.path ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kIsMacOS) {
|
||||||
|
dir = join((await getLibraryDirectory()).path, "Logs");
|
||||||
|
}
|
||||||
|
final file = File(join(dir, ".spotube_logs"));
|
||||||
|
if (!await file.exists()) {
|
||||||
|
await file.create(recursive: true);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> reportError(
|
||||||
dynamic error, [
|
dynamic error, [
|
||||||
StackTrace? stackTrace,
|
StackTrace? stackTrace,
|
||||||
message = "",
|
message = "",
|
||||||
]) {
|
]) async {
|
||||||
log.e(message, error: error, stackTrace: stackTrace);
|
log.e(message, error: error, stackTrace: stackTrace);
|
||||||
|
|
||||||
|
if (kReleaseMode) {
|
||||||
|
await logFile.writeAsString(
|
||||||
|
"[${DateTime.now()}]---------------------\n"
|
||||||
|
"$error\n$stackTrace\n"
|
||||||
|
"----------------------------------------\n",
|
||||||
|
mode: FileMode.writeOnlyAppend,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user