From 779e1e7caae48c59abce4dfe28fee7124f9bbb5f Mon Sep 17 00:00:00 2001 From: Bruno D'Luka Date: Thu, 19 Oct 2023 19:28:25 -0300 Subject: [PATCH] feat: log file --- lib/utils/storage.dart | 34 +++++++++++++++++++ .../device_grid/mobile/device_view.dart | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 0a374b83..3582d361 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +import 'dart:io'; + import 'package:bluecherry_client/utils/constants.dart'; import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; @@ -106,3 +108,35 @@ extension SafeLocalStorageExtension on SafeLocalStorage { return Future.value(); } } + +enum LogType { video, network } + +Future errorLogDirectory() async { + final documentsDir = await getApplicationDocumentsDirectory(); + final logsDir = Directory(path.join(documentsDir.path, 'logs')); + await logsDir.create(recursive: true); + return logsDir; +} + +Future errorLogFile(LogType type) { + return errorLogDirectory().then((dir) async { + final now = DateTime.now(); + final today = DateTime(now.year, now.month, now.day); + final filename = '${today.toIso8601String()}.log'; + final file = File(path.join(dir.path, type.name, filename)); + await file.create(recursive: true); + return file; + }); +} + +Future errorLog(LogType type, String message) async { + final file = await errorLogFile(type); + + final now = DateTime.now(); + final timestamp = now.toIso8601String(); + final log = '$timestamp: $message\n'; + + await file.writeAsString(log, mode: FileMode.append); + + return file; +} diff --git a/lib/widgets/device_grid/mobile/device_view.dart b/lib/widgets/device_grid/mobile/device_view.dart index c2c7348f..f4538805 100644 --- a/lib/widgets/device_grid/mobile/device_view.dart +++ b/lib/widgets/device_grid/mobile/device_view.dart @@ -256,7 +256,7 @@ class DeviceTileState extends State { const Center( child: CircularProgressIndicator.adaptive( valueColor: AlwaysStoppedAnimation(Colors.white), - strokeWidth: 4.4, + strokeWidth: 1.5, ), ), if (video.lastImageUpdate != null)