Skip to content

Commit db0c656

Browse files
PerondasPerondasPerondascloudwebrtc
authored
Logging rework (#316)
* Added default response to cancellation * Added flag to stop ConcurrentModificationError when stopping ua * update. * Changed logger type to the parent class * Added the ability to supply a custom logger. Co-authored-by: Perondas <114622@fhwn.ac.at> Co-authored-by: Perondas <Pperondas@gmail.com> Co-authored-by: cloudwebrtc <duanweiwei1982@gmail.com>
1 parent c7d681f commit db0c656

29 files changed

+304
-307
lines changed

lib/src/config.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,18 @@ void load(Settings src, Settings? dst) {
252252
// Check Mandatory parameters.
253253
checks.mandatory
254254
.forEach((String parameter, Null Function(Settings, Settings?) fun) {
255-
logger.info('Check mandatory parameter => $parameter.');
255+
logger.i('Check mandatory parameter => $parameter.');
256256
fun(src, dst);
257257
});
258258

259259
// Check Optional parameters.
260260
checks.optional
261261
.forEach((String parameter, Null Function(Settings, Settings?) fun) {
262-
logger.debug('Check optional parameter => $parameter.');
262+
logger.d('Check optional parameter => $parameter.');
263263
fun(src, dst);
264264
});
265265
} catch (e) {
266-
logger.error('Failed to load config: ${e.toString()}');
266+
logger.e('Failed to load config: ${e.toString()}');
267267
throw e;
268268
}
269269
}

lib/src/dialog.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Dialog {
8787
}
8888

8989
_ua!.newDialog(this);
90-
logger.debug(
90+
logger.d(
9191
'$type dialog created with status ${_state == DialogStatus.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'}');
9292
}
9393

@@ -113,7 +113,7 @@ class Dialog {
113113
void update(dynamic message, String type) {
114114
_state = DialogStatus.STATUS_CONFIRMED;
115115

116-
logger.debug('dialog ${_id.toString()} changed to CONFIRMED state');
116+
logger.d('dialog ${_id.toString()} changed to CONFIRMED state');
117117

118118
if (type == 'UAC') {
119119
// RFC 3261 13.2.2.4.
@@ -122,7 +122,7 @@ class Dialog {
122122
}
123123

124124
void terminate() {
125-
logger.debug('dialog ${_id.toString()} deleted');
125+
logger.d('dialog ${_id.toString()} deleted');
126126
_ua!.destroyDialog(this);
127127
}
128128

lib/src/digest_authentication.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class DigestAuthentication {
5757
return _ha1;
5858

5959
default:
60-
logger
61-
.error('get() | cannot get ' + parameter.toString() + ' parameter');
60+
logger.e('get() | cannot get ' + parameter.toString() + ' parameter');
6261

6362
return null;
6463
}
@@ -79,7 +78,7 @@ class DigestAuthentication {
7978

8079
if (_algorithm != null) {
8180
if (_algorithm != 'MD5') {
82-
logger.error(
81+
logger.e(
8382
'authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
8483

8584
return false;
@@ -89,14 +88,14 @@ class DigestAuthentication {
8988
}
9089

9190
if (_nonce == null) {
92-
logger.error(
91+
logger.e(
9392
'authenticate() | challenge without Digest nonce, authentication aborted');
9493

9594
return false;
9695
}
9796

9897
if (_realm == null) {
99-
logger.error(
98+
logger.e(
10099
'authenticate() | challenge without Digest realm, authentication aborted');
101100

102101
return false;
@@ -106,15 +105,15 @@ class DigestAuthentication {
106105
if (_credentials.password == null) {
107106
// If ha1 is not provided we cannot authenticate.
108107
if (_credentials.ha1 == null) {
109-
logger.error(
108+
logger.e(
110109
'authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
111110

112111
return false;
113112
}
114113

115114
// If the realm does not match the stored realm we cannot authenticate.
116115
if (_credentials.realm != _realm) {
117-
logger.error(
116+
logger.e(
118117
'authenticate() | no plain SIP password, and stored "realm" does not match the given "realm", cannot authenticate [stored:"${_credentials.realm}", given:"$_realm"]');
119118

120119
return false;
@@ -129,7 +128,7 @@ class DigestAuthentication {
129128
_qop = 'auth';
130129
} else {
131130
// Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
132-
logger.error(
131+
logger.e(
133132
'authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
134133

135134
return false;
@@ -175,7 +174,7 @@ class DigestAuthentication {
175174
a2 = '${SipMethodHelper.getName(_method)}:$_uri';
176175
ha2 = utils.calculateMD5(a2);
177176

178-
logger.debug('authenticate() | using qop=auth [a2:$a2]');
177+
logger.d('authenticate() | using qop=auth [a2:$a2]');
179178

180179
// Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
181180
_response =
@@ -186,7 +185,7 @@ class DigestAuthentication {
186185
'${SipMethodHelper.getName(_method)}:$_uri:${utils.calculateMD5(body ?? '')}';
187186
ha2 = utils.calculateMD5(a2);
188187

189-
logger.debug('authenticate() | using qop=auth-int [a2:$a2]');
188+
logger.d('authenticate() | using qop=auth-int [a2:$a2]');
190189

191190
// Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
192191
_response =
@@ -196,13 +195,13 @@ class DigestAuthentication {
196195
a2 = '${SipMethodHelper.getName(_method)}:$_uri';
197196
ha2 = utils.calculateMD5(a2);
198197

199-
logger.debug('authenticate() | using qop=null [a2:$a2]');
198+
logger.d('authenticate() | using qop=null [a2:$a2]');
200199

201200
// Response = MD5(HA1:nonce:HA2).
202201
_response = utils.calculateMD5('$_ha1:$_nonce:$ha2');
203202
}
204203

205-
logger.debug('authenticate() | response generated');
204+
logger.d('authenticate() | response generated');
206205

207206
return true;
208207
}

lib/src/event_manager/event_manager.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class EventManager {
6969
targets.remove(listener);
7070
targets.add(listener);
7171
} catch (e, s) {
72-
logger.error(e.toString(), null, s);
72+
logger.e(e.toString(), null, s);
7373
}
7474
}
7575

@@ -88,9 +88,9 @@ class EventManager {
8888
if (targets == null) {
8989
return;
9090
}
91-
// logger.warn("removing $eventType on $listener");
91+
// logger.w("removing $eventType on $listener");
9292
if (!targets.remove(listener)) {
93-
logger.warn('Failed to remove any listeners for EventType $eventType');
93+
logger.w('Failed to remove any listeners for EventType $eventType');
9494
}
9595
}
9696

@@ -105,10 +105,10 @@ class EventManager {
105105

106106
for (dynamic target in copy) {
107107
try {
108-
// logger.warn("invoking $event on $target");
108+
// logger.w("invoking $event on $target");
109109
target(event);
110110
} catch (e, s) {
111-
logger.error(e.toString(), null, s);
111+
logger.e(e.toString(), null, s);
112112
}
113113
}
114114
}

lib/src/logger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:logger/logger.dart';
44
import 'enum_helper.dart';
55
import 'stack_trace_nj.dart';
66

7-
final Log logger = Log();
7+
Logger logger = Log();
88

99
class Log extends Logger {
1010
Log();

lib/src/message.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class Message extends EventManager with Applicant {
210210

211211
void _failed(String originator, int? status_code, String cause,
212212
String? reason_phrase) {
213-
logger.debug('MESSAGE failed');
213+
logger.d('MESSAGE failed');
214214
close();
215-
logger.debug('emit "failed"');
215+
logger.d('emit "failed"');
216216
emit(EventCallFailed(
217217
originator: originator,
218218
cause: ErrorCause(
@@ -222,11 +222,11 @@ class Message extends EventManager with Applicant {
222222
}
223223

224224
void _succeeded(String originator, IncomingResponse? response) {
225-
logger.debug('MESSAGE succeeded');
225+
logger.d('MESSAGE succeeded');
226226

227227
close();
228228

229-
logger.debug('emit "succeeded"');
229+
logger.d('emit "succeeded"');
230230

231231
emit(EventSucceeded(originator: originator, response: response));
232232
}

lib/src/options.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class Options extends EventManager with Applicant {
210210

211211
void _failed(String originator, int? status_code, String cause,
212212
String? reason_phrase) {
213-
logger.debug('OPTIONS failed');
213+
logger.d('OPTIONS failed');
214214
close();
215-
logger.debug('emit "failed"');
215+
logger.d('emit "failed"');
216216
emit(EventCallFailed(
217217
originator: originator,
218218
cause: ErrorCause(
@@ -222,11 +222,11 @@ class Options extends EventManager with Applicant {
222222
}
223223

224224
void _succeeded(String originator, IncomingResponse? response) {
225-
logger.debug('OPTIONS succeeded');
225+
logger.d('OPTIONS succeeded');
226226

227227
close();
228228

229-
logger.debug('emit "succeeded"');
229+
logger.d('emit "succeeded"');
230230

231231
emit(EventSucceeded(originator: originator, response: response));
232232
}

lib/src/parser.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ IncomingMessage? parseMessage(String data, UA? ua) {
1414
int headerEnd = data.indexOf('\r\n');
1515

1616
if (headerEnd == -1) {
17-
logger.error('parseMessage() | no CRLF found, not a SIP message');
17+
logger.e('parseMessage() | no CRLF found, not a SIP message');
1818
return null;
1919
}
2020

@@ -29,7 +29,7 @@ IncomingMessage? parseMessage(String data, UA? ua) {
2929
}
3030

3131
if (parsed == -1) {
32-
logger.error(
32+
logger.e(
3333
'parseMessage() | error parsing first line of SIP message: "$firstLine"');
3434

3535
return null;
@@ -60,15 +60,15 @@ IncomingMessage? parseMessage(String data, UA? ua) {
6060
}
6161
// Data.indexOf returned -1 due to a malformed message.
6262
else if (headerEnd == -1) {
63-
logger.error('parseMessage() | malformed message');
63+
logger.e('parseMessage() | malformed message');
6464

6565
return null;
6666
}
6767

6868
parsed = parseHeader(message, data, headerStart, headerEnd);
6969

7070
if (parsed != true) {
71-
logger.error('parseMessage() |' + parsed['error']);
71+
logger.e('parseMessage() |' + parsed['error']);
7272
return null;
7373
}
7474

lib/src/registrator.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Registrator {
122122

123123
void register() {
124124
if (_registering) {
125-
logger.debug('Register request in progress...');
125+
logger.d('Register request in progress...');
126126
return;
127127
}
128128

@@ -132,7 +132,7 @@ class Registrator {
132132
.add('Contact: $_contact;expires=$_expires$_extraContactParams');
133133
extraHeaders.add('Expires: $_expires');
134134

135-
logger.warn(_contact);
135+
logger.w(_contact);
136136

137137
OutgoingRequest request = OutgoingRequest(
138138
SipMethod.REGISTER,
@@ -180,7 +180,7 @@ class Registrator {
180180
_registering = false;
181181

182182
if (!event.response!.hasHeader('Contact')) {
183-
logger.debug(
183+
logger.d(
184184
'no Contact header in response to REGISTER, response ignored');
185185
return;
186186
}
@@ -194,7 +194,7 @@ class Registrator {
194194
(dynamic element) => element.uri.user == _ua!.contact!.uri!.user);
195195

196196
if (contact == null) {
197-
logger.debug('no Contact header pointing to us, response ignored');
197+
logger.d('no Contact header pointing to us, response ignored');
198198
return;
199199
}
200200

@@ -256,8 +256,7 @@ class Registrator {
256256
register();
257257
} else {
258258
// This response MUST contain a Min-Expires header field.
259-
logger.debug(
260-
'423 response received for REGISTER without Min-Expires');
259+
logger.d('423 response received for REGISTER without Min-Expires');
261260

262261
_registrationFailure(
263262
event.response, DartSIP_C.CausesType.SIP_FAILURE_CODE);
@@ -277,7 +276,7 @@ class Registrator {
277276

278277
void unregister(bool unregister_all) {
279278
if (_registered == null) {
280-
logger.debug('already unregistered');
279+
logger.d('already unregistered');
281280

282281
return;
283282
}

lib/src/request_sender.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class RequestSender {
101101

102102
// Verify it seems a valid challenge.
103103
if (challenge == null) {
104-
logger.debug(
104+
logger.d(
105105
'${response.status_code} with wrong or missing challenge, cannot authenticate');
106106
_eventHandlers.emit(EventOnReceiveResponse(response: response));
107107

0 commit comments

Comments
 (0)