Skip to content

Commit a918d2a

Browse files
committed
#355: fixed logs not uploading correctly
1 parent a092d2b commit a918d2a

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

lib/repository/logging/base_logging_repository.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ abstract class BaseLoggingRepository {
1616

1717
String tempLogPath = '/logs';
1818

19-
String get userId;
20-
2119
void startLogging() {
2220
_secureLogStorage.init();
2321
LoggingFactory.configure(LoggingConfiguration(onLog: (value) => storeLogLine(value)));
@@ -26,16 +24,14 @@ abstract class BaseLoggingRepository {
2624
void storeLogLine(String line) => _loggerLock.synchronized(() => _secureLogStorage.storeLogLine(line));
2725

2826
Future<void> uploadLog(DateTime date) async {
29-
final applicationDirectory = await getApplicationDocumentsDirectory();
27+
final applicationDirectory = await getApplicationCacheDirectory();
3028
final file = File('${applicationDirectory.path}$tempLogPath');
3129
if (file.existsSync()) {
3230
file.deleteSync();
3331
file.createSync();
3432
}
3533
final log = await _secureLogStorage.getLogFromDate(date);
36-
for (final line in log) {
37-
file.writeAsStringSync(line);
38-
}
34+
await file.writeAsString(log.join('\n'));
3935
await uploadFile(file, date);
4036
file.deleteSync();
4137
}

lib/repository/logging/logging_repository.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ class LoggingRepository extends BaseLoggingRepository {
1414
super.secureLogStorage,
1515
);
1616

17-
@override
18-
String get userId => 'TestUser';
19-
2017
@override
2118
Future<void> uploadFile(File file, DateTime date) async {
22-
final ref = _firebaseStorage.ref('logs/$userId/${date.shortDateFormat}.txt');
19+
const userId = 'TestUser';
20+
final ref = _firebaseStorage.ref('logs/$userId-${date.dottedShortDateFormat}.txt');
2321
await ref.putFile(file);
2422
}
2523
}

lib/util/extension/date_time_extension.dart

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ extension DateTimeExtentions on DateTime {
99

1010
String get shortDateFormat => _formatDateWithFormatString(formatString: 'dd/MM/yyyy');
1111

12+
String get dottedShortDateFormat => _formatDateWithFormatString(formatString: 'dd.MM.yyyy');
13+
1214
String get shortDateWeekdayFormat => _formatDateWithFormatString(formatString: 'EEEE dd/MM/yyyy');
1315

1416
String _formatDateWithFormatString({required String formatString}) {

lib/viewmodel/log_detail/log_detail_viewmodel.dart

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class LogDetailViewModel with ChangeNotifierEx {
3333
_isLoading = true;
3434
notifyListeners();
3535
await _loggingRepository.uploadLog(_date);
36+
_isLoading = false;
3637
if (disposed) return;
3738
notifyListeners();
3839
}

0 commit comments

Comments
 (0)