From 071f15b067700c5ff109d6a7bf6717839393ec28 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 7 Nov 2020 15:31:16 +0100 Subject: [PATCH] Bug Report: Send logs for today and yesterday --- lib/utils/logger.dart | 23 +++++++++++++++++------ lib/widgets/app_drawer.dart | 3 +-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/utils/logger.dart b/lib/utils/logger.dart index 43228ae2..7538d3ea 100644 --- a/lib/utils/logger.dart +++ b/lib/utils/logger.dart @@ -115,22 +115,20 @@ class Log { } static Iterable fetchLogs() sync* { - var now = DateTime.now(); + var today = DateTime.now(); - var yesterday = now.add(-1.days).toString().substring(0, 10); + var yesterday = today.add(-1.days); for (var msg in fetchLogsForDate(yesterday)) { yield msg; } - var today = now.toString().substring(0, 10); for (var msg in fetchLogsForDate(today)) { yield msg; } } - static Iterable fetchLogsForDate(String date) sync* { - var filePath = p.join(logFolderPath, '$date.jsonl'); - var file = File(filePath); + static Iterable fetchLogsForDate(DateTime date) sync* { + var file = File(filePathForDate(date)); if (!file.existsSync()) { return; } @@ -149,6 +147,19 @@ class Log { var date = dt.toString().substring(0, 10); return p.join(logFolderPath, '$date.jsonl'); } + + static List filePathsForDates(int n) { + var today = DateTime.now(); + var l = []; + for (var i = 0; i < n; i++) { + var fp = filePathForDate(today - Duration(days: i * -1)); + if (File(fp).existsSync()) { + l.add(fp); + } + } + + return l; + } } class LogMessage { diff --git a/lib/widgets/app_drawer.dart b/lib/widgets/app_drawer.dart index 3beb2147..436ecc2c 100644 --- a/lib/widgets/app_drawer.dart +++ b/lib/widgets/app_drawer.dart @@ -164,14 +164,13 @@ class AppDrawer extends StatelessWidget { onTap: () async { var platform = Platform.operatingSystem; var versionText = await getVersionString(); - var appLogsFilePath = Log.filePathForDate(DateTime.now()); final Email email = Email( body: "Hey!\n\nI found a bug in GitJournal - \n \n\nVersion: $versionText\nPlatform: $platform", subject: 'GitJournal Bug', recipients: ['bugs@gitjournal.io'], - attachmentPaths: [appLogsFilePath], + attachmentPaths: Log.filePathsForDates(2), ); await FlutterEmailSender.send(email);