Skip to content

Commit

Permalink
feat: log file
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Oct 19, 2023
1 parent 6547f3a commit 779e1e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'dart:io';

import 'package:bluecherry_client/utils/constants.dart';
import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
Expand Down Expand Up @@ -106,3 +108,35 @@ extension SafeLocalStorageExtension on SafeLocalStorage {
return Future.value();
}
}

enum LogType { video, network }

Future<Directory> errorLogDirectory() async {
final documentsDir = await getApplicationDocumentsDirectory();
final logsDir = Directory(path.join(documentsDir.path, 'logs'));
await logsDir.create(recursive: true);
return logsDir;
}

Future<File> errorLogFile(LogType type) {
return errorLogDirectory().then<File>((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<File> 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;
}
2 changes: 1 addition & 1 deletion lib/widgets/device_grid/mobile/device_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class DeviceTileState extends State<DeviceTile> {
const Center(
child: CircularProgressIndicator.adaptive(
valueColor: AlwaysStoppedAnimation(Colors.white),
strokeWidth: 4.4,
strokeWidth: 1.5,
),
),
if (video.lastImageUpdate != null)
Expand Down

0 comments on commit 779e1e7

Please sign in to comment.