Skip to content

Commit

Permalink
Systematic use of Logging libray.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralu committed Jun 12, 2024
1 parent b8197d2 commit 956a1bb
Show file tree
Hide file tree
Showing 40 changed files with 303 additions and 336 deletions.
15 changes: 10 additions & 5 deletions lib/application/account/account_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ part of 'providers.dart';

class _AccountNotifier
extends AutoDisposeFamilyAsyncNotifier<Account?, String> {
final _logger = Logger('AccountNotifier');
@override
FutureOr<Account?> build(String name) async {
final repository = ref.read(AccountProviders.accountsRepository);
Expand All @@ -22,7 +23,7 @@ class _AccountNotifier

state = AsyncValue.data(account.copyWith());
} catch (e, stack) {
log('Refresh failed', error: e, stackTrace: stack);
_logger.severe('Refresh failed', e, stack);
}
}

Expand All @@ -38,13 +39,17 @@ class _AccountNotifier

Future<void> refreshRecentTransactions() => _refresh(
(account) async {
log('${DateTime.now()} Start method refreshRecentTransactions for ${account.nameDisplayed}');
_logger.fine(
'Start method refreshRecentTransactions for ${account.nameDisplayed}',
);
await Future.wait([
_refreshRecentTransactions(account),
_refreshBalance(account),
account.updateFungiblesTokens(),
]);
log('${DateTime.now()} End method refreshRecentTransactions for ${account.nameDisplayed}');
_logger.fine(
'End method refreshRecentTransactions for ${account.nameDisplayed}',
);
},
);

Expand Down Expand Up @@ -77,7 +82,7 @@ class _AccountNotifier

Future<void> refreshAll() => _refresh(
(account) async {
log('${DateTime.now()} Start method refreshAll');
_logger.fine('Start method refreshAll');
final session = ref.read(SessionProviders.session).loggedIn!;
final tokenInformation = await ref.read(
NFTProviders.getNFTList(
Expand All @@ -96,7 +101,7 @@ class _AccountNotifier
tokenInformation.$2,
),
]);
log('${DateTime.now()} End method refreshAll');
_logger.fine('End method refreshAll');
},
);
}
2 changes: 1 addition & 1 deletion lib/application/account/providers.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:async';
import 'dart:developer';

import 'package:aewallet/application/connectivity_status.dart';
import 'package:aewallet/application/nft/nft.dart';
Expand All @@ -12,6 +11,7 @@ import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/model/data/account_token.dart';
import 'package:collection/collection.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'account_notifier.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/application/authentication/authentication.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:developer';

import 'package:aewallet/domain/models/authentication.dart';
import 'package:aewallet/domain/repositories/authentication.dart';
Expand All @@ -13,6 +12,7 @@ import 'package:aewallet/model/privacy_mask_option.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'authentication.freezed.dart';
Expand Down Expand Up @@ -70,7 +70,7 @@ abstract class AuthenticationProviders {
static final authenticationGuard = AsyncNotifierProvider<
AuthenticationGuardNotifier, AuthenticationGuardState>(
AuthenticationGuardNotifier.new,
name: AuthenticationGuardNotifier.logName,
name: AuthenticationGuardNotifier._logger.name,
);

static final passwordAuthentication = StateNotifierProvider<
Expand Down
20 changes: 9 additions & 11 deletions lib/application/authentication/auto_lock_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ typedef LastInteractionDateValue = ({

class LastInteractionDateNotifier
extends AsyncNotifier<LastInteractionDateValue> {
static const _logName = 'AuthenticationGuard-LastInteractionDateProvider';
static final _logger =
Logger('AuthenticationGuard-LastInteractionDateProvider');

@override
FutureOr<LastInteractionDateValue> build() async {
Expand Down Expand Up @@ -40,7 +41,7 @@ class LastInteractionDateNotifier
await ref
.read(AuthenticationProviders.authenticationRepository)
.setLastInteractionDate(date);
log('persist $date', name: _logName);
_logger.info('persist $date');
state = AsyncValue.data(
(
date: date,
Expand All @@ -50,7 +51,7 @@ class LastInteractionDateNotifier
}

Future<void> clear() async {
log('clear storage', name: _logName);
_logger.fine('clear storage');

await ref
.read(AuthenticationProviders.authenticationRepository)
Expand All @@ -68,7 +69,7 @@ class LastInteractionDateNotifier
final _lastInteractionDateNotifierProvider = AsyncNotifierProvider<
LastInteractionDateNotifier, LastInteractionDateValue>(
LastInteractionDateNotifier.new,
name: LastInteractionDateNotifier._logName,
name: LastInteractionDateNotifier._logger.name,
);

final _vaultLockedProvider = Provider<bool>(
Expand Down Expand Up @@ -104,7 +105,7 @@ class AuthenticationGuardState with _$AuthenticationGuardState {
@Riverpod(keepAlive: true)
class AuthenticationGuardNotifier
extends AsyncNotifier<AuthenticationGuardState> {
static const logName = 'AuthenticationGuard-Provider';
static final _logger = Logger('AuthenticationGuard-Provider');

@override
Future<AuthenticationGuardState> build() async {
Expand Down Expand Up @@ -178,9 +179,8 @@ class AuthenticationGuardNotifier
}

Future<void> scheduleNextStartupAutolock() async {
log(
_logger.info(
'Schedule next startup Autolock',
name: logName,
);

final loadedState = state.valueOrNull;
Expand All @@ -193,9 +193,8 @@ class AuthenticationGuardNotifier
}

void scheduleAutolock() {
log(
_logger.info(
'Schedule Autolock',
name: logName,
);

final loadedState = state.valueOrNull;
Expand All @@ -207,9 +206,8 @@ class AuthenticationGuardNotifier
}

Future<void> unscheduleAutolock() async {
log(
_logger.info(
'Unschedule Autolock',
name: logName,
);
await ref.read(_lastInteractionDateNotifierProvider.notifier).clear();
}
Expand Down
17 changes: 8 additions & 9 deletions lib/application/check_transaction_worker/provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:developer';

import 'package:aewallet/application/account/providers.dart';
import 'package:aewallet/application/connectivity_status.dart';
Expand All @@ -9,6 +8,7 @@ import 'package:aewallet/service/app_service.dart';
import 'package:aewallet/util/get_it_instance.dart';
import 'package:archethic_lib_dart/archethic_lib_dart.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'provider.g.dart';
Expand All @@ -22,23 +22,23 @@ abstract class CheckTransactionsProvider {
class _CheckTransactionNotifier
extends AsyncNotifier<List<ReceivedTransaction>> {
Timer? _checkTransactionsTimer;
static final _logger = Logger('CheckTransactionScheduler');

Future<void> _cancelCheck() async {
if (_checkTransactionsTimer == null) return;
log('cancelling scheduler', name: 'CheckTransactionScheduler');
_logger.info('cancelling scheduler');
_checkTransactionsTimer?.cancel();
_checkTransactionsTimer = null;
}

Future<void> _scheduleCheck() async {
if (_checkTransactionsTimer != null && _checkTransactionsTimer!.isActive) {
log(
_logger.info(
'start abort : scheduler already running',
name: 'CheckTransactionScheduler',
);
return;
}
log('starting scheduler', name: 'CheckTransactionScheduler');
_logger.info('starting scheduler');

_checkTransactionsTimer = Timer.periodic(
const Duration(seconds: 30),
Expand Down Expand Up @@ -137,11 +137,10 @@ class _CheckTransactionNotifier

state = AsyncValue.data(transactionsToNotify);
} catch (e, stack) {
log(
_logger.severe(
'refresh failed.',
name: 'CheckTransactionScheduler',
error: e,
stackTrace: stack,
e,
stack,
);
}
},
Expand Down
4 changes: 2 additions & 2 deletions lib/application/migrations/437.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ part of 'migration_manager.dart';
final migration_437 = LocalDataMigration(
minAppVersion: 437,
run: (ref) async {
final logger = Logger('DataMigration - 437');
// We need to reload keychain because of account's name structure change
// https://github.com/archethic-foundation/archethic-wallet/pull/759
if (ref.read(SessionProviders.session).isLoggedOut) {
log(
logger.info(
'Skipping migration 437 process : user logged out.',
name: logName,
);
return;
}
Expand Down
18 changes: 9 additions & 9 deletions lib/application/migrations/526.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ part of 'migration_manager.dart';
final migration_526 = LocalDataMigration(
minAppVersion: 526,
run: (ref) async {
const logName = 'DataMigration_EncryptedPassword';
final logger = Logger('DataMigration_EncryptedPassword');

const _kSourceBox = '_vaultBox';
const _kDestinationBox = 'NonWebAuthentication';
Expand All @@ -20,13 +20,13 @@ final migration_526 = LocalDataMigration(
Future<void> _migratePassword(Box sourceBox, Box destinationBox) async {
final encryptedPassword = sourceBox.get(_kPassword);
if (encryptedPassword == null) {
log('No password to migrate', name: logName);
logger.info('No password to migrate');
return;
}

final seed = sourceBox.get(_kSeed);
if (seed == null) {
log('No password to migrate', name: logName);
logger.info('No password to migrate');
return;
}

Expand All @@ -38,9 +38,9 @@ final migration_526 = LocalDataMigration(
await destinationBox.put(_kPassword, rawPassword);
await sourceBox.delete(_kPassword);

log('Password migrated', name: logName);
logger.info('Password migrated');
} catch (e) {
log('Password decryption failed', name: logName);
logger.severe('Password decryption failed');
return;
}
}
Expand All @@ -52,13 +52,13 @@ final migration_526 = LocalDataMigration(
) async {
final data = sourceBox.get(key);
if (data == null) {
log('No $key to migrate', name: logName);
logger.info('No $key to migrate');
return;
}

await destinationBox.put(key, data);
await sourceBox.delete(key);
log('$key migrated', name: logName);
logger.info('$key migrated');
}

Future<HiveCipher?> _prepareCipher() async {
Expand All @@ -81,7 +81,7 @@ final migration_526 = LocalDataMigration(
encryptionCipher: cipher,
);
} catch (e) {
log('Unable to open box', name: logName);
logger.severe('Unable to open box');
return null;
}
}
Expand All @@ -94,7 +94,7 @@ final migration_526 = LocalDataMigration(
}

if (sourceBox == null) {
log('No authentication data to migrate', name: logName);
logger.info('No authentication data to migrate');
return;
}

Expand Down
Loading

0 comments on commit 956a1bb

Please sign in to comment.