fix(core): Allow disabling logging of all incoming and outgoing data

This commit is contained in:
PapaTutuWawa 2023-09-29 20:53:29 +02:00
parent 41b789fa28
commit 87866bf3f5
4 changed files with 19 additions and 5 deletions

View File

@ -1,3 +1,8 @@
## 0.4.0
- Keep version in sync with moxxmpp
- *BREAKING*: `TCPSocketWrapper` now takes a boolean parameter that enables logging of all incoming and outgoing data.
## 0.3.1
- Keep version in sync with moxxmpp

View File

@ -5,7 +5,7 @@ import 'package:test/test.dart';
Future<void> _runTest(String domain) async {
var gotTLSException = false;
final socket = TCPSocketWrapper();
final socket = TCPSocketWrapper(true);
final log = Logger('TestLogger');
socket.getEventStream().listen((event) {
if (event is XmppSocketTLSFailedEvent) {

View File

@ -19,7 +19,7 @@ void main() {
TestingSleepReconnectionPolicy(10),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
TCPSocketWrapper(),
TCPSocketWrapper(true),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@no-sasl.badxmpp.eu'),
password: 'abc123',
@ -59,7 +59,7 @@ void main() {
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
TCPSocketWrapper(),
TCPSocketWrapper(true),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@no-sasl.badxmpp.eu'),
password: 'abc123',

View File

@ -10,6 +10,11 @@ import 'package:moxxmpp_socket_tcp/src/rfc_2782.dart';
/// TCP socket implementation for XmppConnection
class TCPSocketWrapper extends BaseSocketWrapper {
TCPSocketWrapper(this._logIncomingOutgoing);
/// Flag controlling whether incoming/outgoing data is logged or not.
final bool _logIncomingOutgoing;
/// The underlying Socket/SecureSocket instance.
Socket? _socket;
@ -212,7 +217,9 @@ class TCPSocketWrapper extends BaseSocketWrapper {
_socketSubscription = _socket!.listen(
(List<int> event) {
final data = utf8.decode(event);
_log.finest('<== $data');
if (_logIncomingOutgoing) {
_log.finest('<== $data');
}
_dataStream.add(data);
},
onError: (Object error) {
@ -297,7 +304,9 @@ class TCPSocketWrapper extends BaseSocketWrapper {
return;
}
_log.finest('==> $data');
if (_logIncomingOutgoing) {
_log.finest('==> $data');
}
try {
_socket!.write(data);