Skip to content
Merged

Logging #1082

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions lib/db/db_version_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import '../utilities/constants.dart';
import '../utilities/flutter_secure_storage_interface.dart';
import '../utilities/logger.dart';
import '../utilities/prefs.dart';
import '../utilities/stack_file_system.dart';
import '../utilities/util.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
import 'hive/db.dart';
import 'isar/main_db.dart';
Expand All @@ -43,7 +45,7 @@ class DbVersionMigrator with WalletDB {
// safe to skip to v11 for campfire
fromVersion = 11;
}
Logging.instance.log(
Logging.instance.logd(
"Running migrate fromVersion $fromVersion",
level: LogLevel.Warning,
);
Expand Down Expand Up @@ -103,7 +105,7 @@ class DbVersionMigrator with WalletDB {
} catch (e) {
// default to 2 for now
latestSetId = 2;
Logging.instance.log(
Logging.instance.logd(
"Failed to fetch latest coin id during firo db migrate: $e \nUsing a default value of 2",
level: LogLevel.Warning,
);
Expand Down Expand Up @@ -144,7 +146,6 @@ class DbVersionMigrator with WalletDB {
),
});
}
Logger.print("newcoins $coins", normalLength: false);
await DB.instance.put<dynamic>(
boxName: walletInfo.walletId,
key: '_lelantus_coins',
Expand Down Expand Up @@ -443,6 +444,20 @@ class DbVersionMigrator with WalletDB {
// try to continue migrating
return await migrate(13, secureStore: secureStore);

case 13:
// migrate
await _v13(secureStore);

// update version
await DB.instance.put<dynamic>(
boxName: DB.boxNameDBInfo,
key: "hive_data_version",
value: 14,
);

// try to continue migrating
return await migrate(14, secureStore: secureStore);

default:
// finally return
return;
Expand Down Expand Up @@ -734,4 +749,31 @@ class DbVersionMigrator with WalletDB {
);
}
}

Future<void> _v13(SecureStorageInterface secureStore) async {
if (!(Util.isArmLinux || Util.isTestEnv)) {
// open logs db
final isar = await Isar.open(
[isar_models.LogSchema],
directory: (await StackFileSystem.applicationIsarDirectory()).path,
inspector: false,
maxSizeMiB: 512,
);

// fetch all logs
final allLogs = await isar.logs.where().findAll();

// migrate to simple file based logs. Date/time may be out of order
for (final log in allLogs) {
Logging.instance.log(
log.logLevel.getLoggerLevel(),
"MIGRATED LOG::=> ${log.message}",
time: DateTime.fromMillisecondsSinceEpoch(log.timestampInMillisUTC),
);
}

// finally delete logs db
await isar.close(deleteFromDisk: true);
}
}
}
4 changes: 2 additions & 2 deletions lib/db/hive/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DB {
AppConfig.getCryptoCurrencyFor(jsonObject["coin"] as String);
return false;
} catch (e, s) {
Logging.instance.log(
Logging.instance.logd(
"Error, ${jsonObject["coin"]} does not exist, $name wallet cannot be loaded",
level: LogLevel.Error,
);
Expand Down Expand Up @@ -343,7 +343,7 @@ class DB {
await DB.instance.deleteBoxFromDisk(boxName: "theme");
return true;
} catch (e, s) {
Logging.instance.log("$e $s", level: LogLevel.Error);
Logging.instance.logd("$e $s", level: LogLevel.Error);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/db/sqlite/firo_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ part 'firo_cache_writer.dart';
/// Temporary debugging log function for this file
void _debugLog(Object? object) {
if (kDebugMode) {
Logging.instance.log(
Logging.instance.logd(
object,
level: LogLevel.Debug,
);
Expand Down
6 changes: 3 additions & 3 deletions lib/db/sqlite/firo_cache_coordinator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ abstract class FiroCacheCoordinator {
? await usedTagsCacheFile.length()
: 0;

Logging.instance.log(
Logging.instance.logd(
"Spark cache used tags size: $tagsSize",
level: LogLevel.Debug,
);
Logging.instance.log(
Logging.instance.logd(
"Spark cache anon set size: $setSize",
level: LogLevel.Debug,
);
Expand Down Expand Up @@ -111,7 +111,7 @@ abstract class FiroCacheCoordinator {
progressUpdated?.call(prevSize, meta.size);

if (prevMeta?.blockHash == meta.blockHash) {
Logging.instance.log(
Logging.instance.logd(
"prevMeta?.blockHash == meta.blockHash",
level: LogLevel.Debug,
);
Expand Down
8 changes: 4 additions & 4 deletions lib/electrumx_rpc/cached_electrumx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ class CachedElectrumXClient {
}
// save set to db
await box.put(groupId, set);
Logging.instance.log(
Logging.instance.logd(
"Updated current anonymity set for ${cryptoCurrency.identifier} with group ID $groupId",
level: LogLevel.Info,
);
}

return set;
} catch (e, s) {
Logging.instance.log(
Logging.instance.logd(
"Failed to process CachedElectrumX.getAnonymitySet(): $e\n$s",
level: LogLevel.Error,
);
Expand Down Expand Up @@ -162,7 +162,7 @@ class CachedElectrumXClient {
return Map<String, dynamic>.from(cachedTx);
}
} catch (e, s) {
Logging.instance.log(
Logging.instance.logd(
"Failed to process CachedElectrumX.getTransaction(): $e\n$s",
level: LogLevel.Error,
);
Expand Down Expand Up @@ -212,7 +212,7 @@ class CachedElectrumXClient {

return resultingList;
} catch (e, s) {
Logging.instance.log(
Logging.instance.logd(
"Failed to process CachedElectrumX.getUsedCoinSerials(): $e\n$s",
level: LogLevel.Error,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/electrumx_rpc/client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ClientManager {
_heightCompleters[key]!.complete(event.height);
}
},
onError: (Object err, StackTrace s) => Logging.instance.log(
onError: (Object err, StackTrace s) => Logging.instance.logd(
"ClientManager listen: $err\n$s",
level: LogLevel.Error,
),
Expand Down
Loading
Loading