Skip to content

Commit

Permalink
Change the log library from fimber to logging (#657)
Browse files Browse the repository at this point in the history
* Change the log library from fimber to logging

* Fix dart analyzer

* Uses utc time

* Dart format
  • Loading branch information
ademar111190 authored Oct 9, 2023
1 parent 32d95ab commit 5823fe0
Show file tree
Hide file tree
Showing 73 changed files with 531 additions and 522 deletions.
6 changes: 3 additions & 3 deletions lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:convert';

import 'package:breez_sdk/bridge_generated.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';

final _log = FimberLog("AppConfig");
final _log = Logger("AppConfig");

class AppConfig {
final String apiKey = const String.fromEnvironment("API_KEY");
Expand All @@ -17,7 +17,7 @@ class AppConfig {
deviceKey: base64.decode(glKey),
);
} catch (e) {
_log.w("Failed to parse partner credentials: $e");
_log.warning("Failed to parse partner credentials: $e");
return null;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/background/background_task_handler.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'dart:io';

import 'package:c_breez/background/payment_hash_poller.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';
import 'package:workmanager/workmanager.dart';

final log = FimberLog("BackgroundTaskManager");
final _log = Logger("BackgroundTaskManager");

@pragma('vm:entry-point') // Mandatory if the App is obfuscated or using Flutter 3.1+
class BackgroundTaskManager {
final timeoutDuration = Duration(seconds: (Platform.isIOS) ? 30 : 60);

handleBackgroundTask() {
Workmanager().executeTask((String taskName, Map<String, dynamic>? inputData) async {
log.i("Executing task: $taskName\nInput data: ${inputData.toString()}");
_log.info("Executing task: $taskName\nInput data: ${inputData.toString()}");
if (inputData != null) {
switch (inputData["notification_type"]) {
case "payment_received":
Expand Down
6 changes: 3 additions & 3 deletions lib/background/breez_message_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'dart:io';

import 'package:c_breez/background/breez_service_initializer.dart';
import 'package:c_breez/main.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:workmanager/workmanager.dart';

final log = FimberLog("BreezMessageHandler");
final _log = Logger("BreezMessageHandler");

@pragma('vm:entry-point') // Mandatory if the App is obfuscated or using Flutter 3.1+
class BreezMessageHandler {
Expand All @@ -15,7 +15,7 @@ class BreezMessageHandler {
BreezMessageHandler(this.message);

Future<void> handleBackgroundMessage() async {
log.i("Handling a background message: ${message.messageId}\nMessage data: ${message.data}");
_log.info("Handling a background message: ${message.messageId}\nMessage data: ${message.data}");
await initializeBreezServices();
await Workmanager().initialize(callbackDispatcher, isInDebugMode: true);

Expand Down
56 changes: 28 additions & 28 deletions lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:c_breez/bloc/account/payment_filters.dart';
import 'package:c_breez/bloc/account/payment_result.dart';
import 'package:c_breez/config.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';
import 'package:flutter_fgbg/flutter_fgbg.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:path/path.dart' as p;
Expand All @@ -27,7 +27,7 @@ const nodeSyncInterval = 60;
// 1. Synchronizing with the node state.
// 2. Abstracting actions exposed by the lightning service.
class AccountBloc extends Cubit<AccountState> with HydratedMixin {
final _log = FimberLog("AccountBloc");
final _log = Logger("AccountBloc");
static const String paymentFilterSettingsKey = "payment_filter_settings";
static const int defaultInvoiceExpiry = Duration.secondsPerHour;

Expand Down Expand Up @@ -82,7 +82,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

Future _startSdkForever() async {
_log.v("starting sdk forever");
_log.fine("starting sdk forever");
await _startSdkOnce();

// in case we failed to start (lack of inet connection probably)
Expand All @@ -104,7 +104,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

Future _startSdkOnce() async {
_log.v("starting sdk once");
_log.fine("starting sdk once");
try {
emit(state.copyWith(connectionStatus: ConnectionStatus.CONNECTING));
final mnemonic = await _credentialsManager.restoreMnemonic();
Expand All @@ -118,7 +118,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {

// Once connected sync sdk periodically on foreground events.
void _onConnected() {
_log.v("on connected");
_log.fine("on connected");
var lastSync = DateTime.fromMillisecondsSinceEpoch(0);
FGBGEvents.stream.listen((event) async {
if (event == FGBGType.foreground && DateTime.now().difference(lastSync).inSeconds > nodeSyncInterval) {
Expand All @@ -133,15 +133,15 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
required sdk.LnUrlWithdrawRequestData reqData,
String? description,
}) async {
_log.v("lnurlWithdraw amount: $amountSats, description: '$description', reqData: $reqData");
_log.fine("lnurlWithdraw amount: $amountSats, description: '$description', reqData: $reqData");
try {
return await _breezLib.lnurlWithdraw(
amountSats: amountSats,
reqData: reqData,
description: description,
);
} catch (e) {
_log.e("lnurlWithdraw error", ex: e);
_log.severe("lnurlWithdraw error", e);
rethrow;
}
}
Expand All @@ -151,43 +151,43 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
required sdk.LnUrlPayRequestData reqData,
String? comment,
}) async {
_log.v("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData");
_log.fine("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData");
try {
return await _breezLib.lnurlPay(
userAmountSat: amount,
reqData: reqData,
comment: comment,
);
} catch (e) {
_log.e("lnurlPay error", ex: e);
_log.severe("lnurlPay error", e);
rethrow;
}
}

Future<sdk.LnUrlCallbackStatus> lnurlAuth({
required sdk.LnUrlAuthRequestData reqData,
}) async {
_log.v("lnurlAuth amount: reqData: $reqData");
_log.fine("lnurlAuth amount: reqData: $reqData");
try {
return await _breezLib.lnurlAuth(reqData: reqData);
} catch (e) {
_log.e("lnurlAuth error", ex: e);
_log.severe("lnurlAuth error", e);
rethrow;
}
}

Future sendPayment(String bolt11, int? amountSats) async {
_log.v("sendPayment: $bolt11, $amountSats");
_log.fine("sendPayment: $bolt11, $amountSats");
try {
await _breezLib.sendPayment(bolt11: bolt11, amountSats: amountSats);
} catch (e) {
_log.e("sendPayment error", ex: e);
_log.severe("sendPayment error", e);
return Future.error(e);
}
}

Future cancelPayment(String bolt11) async {
_log.v("cancelPayment: $bolt11");
_log.fine("cancelPayment: $bolt11");
throw Exception("not implemented");
}

Expand All @@ -196,21 +196,21 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
String description,
int amountSats,
) async {
_log.v("sendSpontaneousPayment: $nodeId, $description, $amountSats");
_log.i("description field is not being used by the SDK yet");
_log.fine("sendSpontaneousPayment: $nodeId, $description, $amountSats");
_log.info("description field is not being used by the SDK yet");
try {
await _breezLib.sendSpontaneousPayment(
nodeId: nodeId,
amountSats: amountSats,
);
} catch (e) {
_log.e("sendSpontaneousPayment error", ex: e);
_log.severe("sendSpontaneousPayment error", e);
return Future.error(e);
}
}

Future<bool> isValidBitcoinAddress(String? address) async {
_log.v("isValidBitcoinAddress: $address");
_log.fine("isValidBitcoinAddress: $address");
if (address == null) return false;
return _breezLib.isValidBitcoinAddress(address);
}
Expand All @@ -223,10 +223,10 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
bool channelCreationPossible, {
int? channelMinimumFee,
}) {
_log.v("validatePayment: $amount, $outgoing, $channelMinimumFee");
_log.fine("validatePayment: $amount, $outgoing, $channelMinimumFee");
var accState = state;
if (amount > accState.maxPaymentAmount) {
_log.v("Amount $amount is bigger than maxPaymentAmount ${accState.maxPaymentAmount}");
_log.fine("Amount $amount is bigger than maxPaymentAmount ${accState.maxPaymentAmount}");
throw PaymentExceededLimitError(accState.maxPaymentAmount);
}

Expand All @@ -246,9 +246,9 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

if (outgoing && amount > accState.maxAllowedToPay) {
_log.v("Outgoing but amount $amount is bigger than ${accState.maxAllowedToPay}");
_log.fine("Outgoing but amount $amount is bigger than ${accState.maxAllowedToPay}");
if (accState.reserveAmount > 0) {
_log.v("Reserve amount ${accState.reserveAmount}");
_log.fine("Reserve amount ${accState.reserveAmount}");
throw PaymentBelowReserveError(accState.reserveAmount);
}
throw const InsufficientLocalBalanceError();
Expand All @@ -260,7 +260,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
int? fromTimestamp,
int? toTimestamp,
}) async {
_log.v("changePaymentFilter: $filter, $fromTimestamp, $toTimestamp");
_log.fine("changePaymentFilter: $filter, $fromTimestamp, $toTimestamp");
_paymentFiltersStreamController.add(
state.paymentFilters.copyWith(
filter: filter,
Expand All @@ -274,7 +274,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
String description = "",
required int amountSats,
}) async {
_log.v("addInvoice: $description, $amountSats");
_log.fine("addInvoice: $description, $amountSats");

final requestData = sdk.ReceivePaymentRequest(amountSats: amountSats, description: description);
final responseData = await _breezLib.receivePayment(reqData: requestData);
Expand All @@ -292,12 +292,12 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

Future<List<File>> exportCredentialFiles() async {
_log.v("exportCredentialFiles");
_log.fine("exportCredentialFiles");
return _credentialsManager.exportCredentials();
}

void recursiveFolderCopySync(String path1, String path2) {
_log.v("recursiveFolderCopySync: $path1, $path2");
_log.fine("recursiveFolderCopySync: $path1, $path2");
Directory dir1 = Directory(path1);
Directory dir2 = Directory(path2);
if (!dir2.existsSync()) {
Expand All @@ -317,7 +317,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

void _listenPaymentResultEvents() {
_log.v("_listenPaymentResultEvents");
_log.fine("_listenPaymentResultEvents");
_breezLib.paymentResultStream.listen((paymentInfo) {
_paymentResultStreamController.add(
PaymentResult(paymentInfo: paymentInfo),
Expand All @@ -328,7 +328,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

void mnemonicsValidated() {
_log.v("mnemonicsValidated");
_log.fine("mnemonicsValidated");
emit(state.copyWith(verificationStatus: VerificationStatus.VERIFIED));
}
}
8 changes: 4 additions & 4 deletions lib/bloc/account/credentials_manager.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';

import 'package:c_breez/services/keychain.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';

class CredentialsManager {
final _log = FimberLog("CredentialsManager");
final _log = Logger("CredentialsManager");
static const String accountMnemonic = "account_mnemonic";

final KeyChain keyChain;
Expand All @@ -17,7 +17,7 @@ class CredentialsManager {
}) async {
try {
await _storeMnemonic(mnemonic);
_log.i("Stored credentials successfully");
_log.info("Stored credentials successfully");
} catch (err) {
throw Exception(err.toString());
}
Expand All @@ -26,7 +26,7 @@ class CredentialsManager {
Future<String> restoreMnemonic() async {
try {
String? mnemonicStr = await keyChain.read(accountMnemonic);
_log.i("Restored credentials successfully");
_log.info("Restored credentials successfully");
return mnemonicStr!;
} catch (err) {
throw Exception(err.toString());
Expand Down
12 changes: 6 additions & 6 deletions lib/bloc/backup/backup_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart' as sdk;
import 'package:c_breez/bloc/backup/backup_state.dart';
import 'package:fimber/fimber.dart';
import 'package:logging/logging.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';

class BackupBloc extends Cubit<BackupState?> {
final _log = FimberLog("BackupBloc");
final _log = Logger("BackupBloc");
final BreezSDK _breezLib;

BackupBloc(this._breezLib) : super(null) {
_listenBackupEvents();
}

_listenBackupEvents() {
_log.v("_listenBackupEvents");
_log.fine("_listenBackupEvents");
_breezLib.backupStream.listen((event) {
_log.i('got state: $event');
_log.info('got state: $event');
if (event is sdk.BreezEvent_BackupStarted) {
emit(BackupState(status: BackupStatus.INPROGRESS));
}
if (event is sdk.BreezEvent_BackupSucceeded) {
_log.i("BreezEvent_BackupSucceeded, backupbloc");
_log.info("BreezEvent_BackupSucceeded, backupbloc");
emit(BackupState(status: BackupStatus.SUCCESS));
}
if (event is sdk.BreezEvent_BackupFailed) {
_log.i("BreezEvent_BackupFailed");
_log.info("BreezEvent_BackupFailed");
emit(BackupState(status: BackupStatus.FAILED));
}
}, onError: (error) {
Expand Down
Loading

0 comments on commit 5823fe0

Please sign in to comment.