Skip to content

Commit

Permalink
Improve logging for mobile development (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ademar111190 authored Oct 19, 2023
1 parent 0cff506 commit ced812d
Show file tree
Hide file tree
Showing 51 changed files with 188 additions and 191 deletions.
40 changes: 20 additions & 20 deletions lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

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

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

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

// Once connected sync sdk periodically on foreground events.
void _onConnected() {
_log.fine("on connected");
_log.info("on connected");
var lastSync = DateTime.fromMillisecondsSinceEpoch(0);
FGBGEvents.stream.listen((event) async {
if (event == FGBGType.foreground && DateTime.now().difference(lastSync).inSeconds > nodeSyncInterval) {
Expand All @@ -135,7 +135,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
required sdk.LnUrlWithdrawRequestData reqData,
String? description,
}) async {
_log.fine("lnurlWithdraw amount: $amountSats, description: '$description', reqData: $reqData");
_log.info("lnurlWithdraw amount: $amountSats, description: '$description', reqData: $reqData");
try {
return await _breezLib.lnurlWithdraw(
amountSats: amountSats,
Expand All @@ -153,7 +153,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
required sdk.LnUrlPayRequestData reqData,
String? comment,
}) async {
_log.fine("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData");
_log.info("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData");
try {
return await _breezLib.lnurlPay(
userAmountSat: amount,
Expand All @@ -169,7 +169,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
Future<sdk.LnUrlCallbackStatus> lnurlAuth({
required sdk.LnUrlAuthRequestData reqData,
}) async {
_log.fine("lnurlAuth amount: reqData: $reqData");
_log.info("lnurlAuth amount: reqData: $reqData");
try {
return await _breezLib.lnurlAuth(reqData: reqData);
} catch (e) {
Expand All @@ -179,7 +179,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

Future sendPayment(String bolt11, int? amountMsat) async {
_log.fine("sendPayment: $bolt11, $amountMsat");
_log.info("sendPayment: $bolt11, $amountMsat");
try {
await _breezLib.sendPayment(bolt11: bolt11, amountMsat: amountMsat);
} catch (e) {
Expand All @@ -189,7 +189,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

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

Expand All @@ -198,7 +198,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
String description,
int amountSats,
) async {
_log.fine("sendSpontaneousPayment: $nodeId, $description, $amountSats");
_log.info("sendSpontaneousPayment: $nodeId, $description, $amountSats");
_log.info("description field is not being used by the SDK yet");
try {
await _breezLib.sendSpontaneousPayment(
Expand All @@ -212,7 +212,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

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

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

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

final requestData = sdk.ReceivePaymentRequest(
amountSats: amountSats, description: description, openingFeeParams: chosenFeeParams);
Expand All @@ -296,7 +296,7 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

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

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

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

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

void mnemonicsValidated() {
_log.fine("mnemonicsValidated");
_log.info("mnemonicsValidated");
emit(state.copyWith(verificationStatus: VerificationStatus.VERIFIED));
}
}
2 changes: 1 addition & 1 deletion lib/bloc/backup/backup_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BackupBloc extends Cubit<BackupState?> {
}

_listenBackupEvents() {
_log.fine("_listenBackupEvents");
_log.info("_listenBackupEvents");
_breezLib.backupStream.listen((event) {
_log.info('got state: $event');
if (event is sdk.BreezEvent_BackupStarted) {
Expand Down
14 changes: 7 additions & 7 deletions lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ class MoonPayBloc extends Cubit<MoonPayState> {

Future<void> fetchMoonpayUrl() async {
try {
_log.fine("fetchMoonpayUrl");
_log.info("fetchMoonpayUrl");
emit(MoonPayState.loading());
final swapInProgress = (await _breezLib.inProgressSwap());

if (swapInProgress != null) {
_log.fine("fetchMoonpayUrl swapInfo: $swapInProgress");
_log.info("fetchMoonpayUrl swapInfo: $swapInProgress");
emit(MoonPayState.swapInProgress(
swapInProgress.bitcoinAddress, swapInProgress.status == sdk.SwapStatus.Expired));
return;
}

sdk.BuyBitcoinRequest reqData = const sdk.BuyBitcoinRequest(provider: sdk.BuyBitcoinProvider.Moonpay);
final buyBitcoinResponse = await _breezLib.buyBitcoin(reqData: reqData);
_log.fine("fetchMoonpayUrl url: ${buyBitcoinResponse.url}");
_log.info("fetchMoonpayUrl url: ${buyBitcoinResponse.url}");
if (buyBitcoinResponse.openingFeeParams != null) {
emit(MoonPayState.urlReady(buyBitcoinResponse));
return;
Expand All @@ -48,7 +48,7 @@ class MoonPayBloc extends Cubit<MoonPayState> {
}

void updateWebViewStatus(WebViewStatus status) {
_log.fine("updateWebViewStatus status: $status");
_log.info("updateWebViewStatus status: $status");
final state = this.state;
if (state is MoonPayStateUrlReady) {
emit(state.copyWith(webViewStatus: status));
Expand All @@ -58,15 +58,15 @@ class MoonPayBloc extends Cubit<MoonPayState> {
}

Future<String> makeExplorerUrl(String address) async {
_log.fine("openExplorer address: $address");
_log.info("openExplorer address: $address");
final mempoolUrl = await _preferences.getMempoolSpaceUrl() ?? (await Config.instance()).defaultMempoolUrl;
final url = "$mempoolUrl/address/$address";
_log.fine("openExplorer url: $url");
_log.info("openExplorer url: $url");
return url;
}

void dispose() {
_log.fine("dispose");
_log.info("dispose");
emit(MoonPayState.initial());
}
}
8 changes: 4 additions & 4 deletions lib/bloc/fee_options/fee_options_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class FeeOptionsBloc extends Cubit<FeeOptionsState> {
/// Lookup the most recent reverse swap pair info using the Boltz API
Future<ReverseSwapPairInfo> fetchReverseSwapFees({int? sendAmountSat}) async {
try {
_log.fine("Estimate reverse swap fees for: $sendAmountSat");
_log.info("Estimate reverse swap fees for: $sendAmountSat");
final req = ReverseSwapFeesRequest(sendAmountSat: sendAmountSat);
ReverseSwapPairInfo reverseSwapPairInfo = await _breezLib.fetchReverseSwapFees(req: req);
_log.fine("Total estimated fees for reverse swap: ${reverseSwapPairInfo.totalEstimatedFees}");
_log.info("Total estimated fees for reverse swap: ${reverseSwapPairInfo.totalEstimatedFees}");
emit(state.copyWith(reverseSwapPairInfo: reverseSwapPairInfo, error: ""));
return reverseSwapPairInfo;
} catch (e) {
Expand All @@ -37,7 +37,7 @@ class FeeOptionsBloc extends Cubit<FeeOptionsState> {
RecommendedFees recommendedFees;
try {
recommendedFees = await _breezLib.recommendedFees();
_log.fine(
_log.info(
"fetchFeeOptions recommendedFees:\nfastestFee: ${recommendedFees.fastestFee},"
"\nhalfHourFee: ${recommendedFees.halfHourFee},\nhourFee: ${recommendedFees.hourFee}.",
);
Expand All @@ -57,7 +57,7 @@ class FeeOptionsBloc extends Cubit<FeeOptionsState> {
throw Exception(getSystemAppLocalizations().node_state_error);
}
final utxos = nodeState.utxos.length;
_log.fine("_retrieveUTXOS utxos: $utxos");
_log.info("_retrieveUTXOS utxos: $utxos");
return utxos;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/bloc/input/input_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ class InputBloc extends Cubit<InputState> {
}

void _initializeInputBloc() async {
_log.config("initializeInputBloc");
_log.info("initializeInputBloc");
await _breezLib.nodeStateStream.firstWhere((nodeState) => nodeState != null);
_watchIncomingInvoices().listen((inputState) => emit(inputState!));
}

void addIncomingInput(String bolt11, InputSource source) {
_log.fine("addIncomingInput: $bolt11 source: $source");
_log.info("addIncomingInput: $bolt11 source: $source");
_decodeInvoiceController.add(InputData(data: bolt11, source: source));
}

Future trackPayment(String paymentHash) async {
await _breezLib.invoicePaidStream.firstWhere((invoice) {
_log.fine("invoice paid: ${invoice.paymentHash} we are waiting for "
_log.info("invoice paid: ${invoice.paymentHash} we are waiting for "
"$paymentHash, same: ${invoice.paymentHash == paymentHash}");
return invoice.paymentHash == paymentHash;
});
}

Stream<InputState?> _watchIncomingInvoices() {
return Rx.merge([
_decodeInvoiceController.stream.doOnData((event) => _log.fine("decodeInvoiceController: $event")),
_decodeInvoiceController.stream.doOnData((event) => _log.info("decodeInvoiceController: $event")),
_lightningLinks.linksNotifications
.map((data) => InputData(data: data, source: InputSource.hyperlink))
.doOnData((event) => _log.fine("lightningLinks: $event")),
.doOnData((event) => _log.info("lightningLinks: $event")),
_device.clipboardStream
.distinct()
.skip(1)
.map((data) => InputData(data: data, source: InputSource.clipboard))
.doOnData((event) => _log.fine("clipboardStream: $event")),
.doOnData((event) => _log.info("clipboardStream: $event")),
]).asyncMap((input) async {
_log.fine("Incoming input: '$input'");
_log.info("Incoming input: '$input'");
// Emit an empty InputState with isLoading to display a loader on UI layer
emit(const InputState.loading());
try {
Expand Down Expand Up @@ -93,7 +93,7 @@ class InputBloc extends Cubit<InputState> {
}

Future<InputState> _handleParsedInput(InputType parsedInput, InputSource source) async {
_log.fine("handleParsedInput: $source => ${_printer.inputTypeToString(parsedInput)}");
_log.info("handleParsedInput: $source => ${_printer.inputTypeToString(parsedInput)}");
InputState result;
if (parsedInput is InputType_Bolt11) {
result = await handlePaymentRequest(parsedInput, source);
Expand Down
14 changes: 7 additions & 7 deletions lib/bloc/network/network_settings_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class NetworkSettingsBloc extends Cubit<NetworkSettingsState> with HydratedMixin
http.Client? httpClient,
}) : _httpClient = httpClient ?? http.Client(),
super(NetworkSettingsState.initial()) {
_fetchMempoolSettings().then((_) => _log.fine("Initial mempool settings read"));
_fetchMempoolSettings().then((_) => _log.info("Initial mempool settings read"));
}

Future<bool> setMempoolUrl(String mempoolUrl) async {
_log.fine("Changing mempool url to: $mempoolUrl");
_log.info("Changing mempool url to: $mempoolUrl");
Uri? uri;
try {
if (mempoolUrl.startsWith(RegExp(r'\d'))) {
_log.fine("Mempool url starts with a digit, adding https://");
_log.info("Mempool url starts with a digit, adding https://");
uri = Uri.parse("https://$mempoolUrl");
} else {
uri = Uri.parse(mempoolUrl);
Expand All @@ -35,7 +35,7 @@ class NetworkSettingsBloc extends Cubit<NetworkSettingsState> with HydratedMixin
return false;
}
if (!uri.hasScheme) {
_log.fine("Mempool url scheme is missing, adding https://");
_log.info("Mempool url scheme is missing, adding https://");
try {
uri = Uri.parse("https://$mempoolUrl");
} catch (e) {
Expand All @@ -58,7 +58,7 @@ class NetworkSettingsBloc extends Cubit<NetworkSettingsState> with HydratedMixin
}

Future<void> resetMempoolSpaceSettings() async {
_log.fine("Resetting mempool url to default");
_log.info("Resetting mempool url to default");
await _preferences.resetMempoolSpaceUrl();
await _fetchMempoolSettings();
}
Expand All @@ -74,10 +74,10 @@ class NetworkSettingsBloc extends Cubit<NetworkSettingsState> with HydratedMixin
}

Future<void> _fetchMempoolSettings() async {
_log.fine("Fetching mempool settings");
_log.info("Fetching mempool settings");
final mempoolUrl = await _preferences.getMempoolSpaceUrl();
final mempoolDefaultUrl = _config.defaultMempoolUrl;
_log.fine("Mempool url fetched: $mempoolUrl, default: $mempoolDefaultUrl");
_log.info("Mempool url fetched: $mempoolUrl, default: $mempoolDefaultUrl");
emit(state.copyWith(
mempoolUrl: mempoolUrl ?? mempoolDefaultUrl,
));
Expand Down
Loading

0 comments on commit ced812d

Please sign in to comment.