From cf5331a026738f5f20d17a1dfef844f62e0ad627 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 15 Sep 2022 13:17:30 +0200 Subject: [PATCH] feat: Introduce logging for logging purposes --- lib/src/omemo/sessionmanager.dart | 9 +++++++-- pubspec.yaml | 1 + test/omemo_test.dart | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 75c85e2..0173491 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:collection/collection.dart'; import 'package:cryptography/cryptography.dart'; import 'package:hex/hex.dart'; +import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; import 'package:omemo_dart/src/crypto.dart'; import 'package:omemo_dart/src/double_ratchet/double_ratchet.dart'; @@ -31,7 +32,8 @@ class OmemoSessionManager { OmemoSessionManager(this._device, this._deviceMap, this._ratchetMap, this._trustManager) : _lock = Lock(), _deviceLock = Lock(), - _eventStreamController = StreamController.broadcast(); + _eventStreamController = StreamController.broadcast(), + _log = Logger('OmemoSessionManager'); /// Deserialise the OmemoSessionManager from JSON data [data]. factory OmemoSessionManager.fromJson(Map data, TrustManager trustManager) { @@ -68,6 +70,9 @@ class OmemoSessionManager { return OmemoSessionManager(device, {}, {}, trustManager); } + + /// Logging + Logger _log; /// Lock for _ratchetMap and _bundleMap final Lock _lock; @@ -304,7 +309,7 @@ class OmemoSessionManager { /// [mapKey] with [oldRatchet]. Future _restoreRatchet(RatchetMapKey mapKey, OmemoDoubleRatchet oldRatchet) async { await _lock.synchronized(() { - print('RESTORING RATCHETS'); + _log.finest('Restoring ratchet ${mapKey.jid}:${mapKey.deviceId}'); _ratchetMap[mapKey] = oldRatchet; // Commit the ratchet diff --git a/pubspec.yaml b/pubspec.yaml index 76d5925..4569e9d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: collection: ^1.16.0 cryptography: ^2.0.5 hex: ^0.2.0 + logging: ^1.0.2 meta: ^1.7.0 pinenacl: ^0.5.1 synchronized: ^3.0.0+2 diff --git a/test/omemo_test.dart b/test/omemo_test.dart index fb893ce..e0a5792 100644 --- a/test/omemo_test.dart +++ b/test/omemo_test.dart @@ -1,9 +1,17 @@ +import 'package:logging/logging.dart'; import 'package:omemo_dart/omemo_dart.dart'; import 'package:omemo_dart/src/trust/always.dart'; import 'package:omemo_dart/src/trust/never.dart'; import 'package:test/test.dart'; void main() { + Logger.root + ..level = Level.ALL + ..onRecord.listen((record) { + // ignore: avoid_print + print('${record.level.name}: ${record.message}'); + }); + test('Test using OMEMO sessions with only one device per user', () async { const aliceJid = 'alice@server.example'; const bobJid = 'bob@other.server.example';