Skip to content

Commit

Permalink
Log more info in http logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Nov 14, 2023
1 parent 694a6d9 commit 9da1d1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,6 @@ class _RealmCore {
// Build request
late HttpClientRequest request;

// this throws if requestMethod is unknown _HttpMethod

switch (method) {
case _HttpMethod.delete:
request = await client.deleteUrl(url);
Expand All @@ -1796,8 +1794,16 @@ class _RealmCore {
request.add(utf8.encode(body));
}

Realm.logger.log(RealmLogLevel.debug, "HTTP Transport: Executing $method $url");

final stopwatch = Stopwatch()..start();

// Do the call..
final response = await request.close();

stopwatch.stop();
Realm.logger.log(RealmLogLevel.debug, "HTTP Transport: Executed $method $url: ${response.statusCode} in ${stopwatch.elapsedMilliseconds} ms");

final responseBody = await response.fold<List<int>>([], (acc, l) => acc..addAll(l)); // gather response

// Report back to core
Expand Down Expand Up @@ -1825,13 +1831,13 @@ class _RealmCore {

responseRef.custom_status_code = _CustomErrorCode.noError.code;
} on SocketException catch (socketEx) {
Realm.logger.log(Level.WARNING, "A SocketException occurred while executing $method $url: $socketEx");
Realm.logger.log(RealmLogLevel.warn, "HTTP Transport: SocketException executing $method $url: $socketEx");
responseRef.custom_status_code = _CustomErrorCode.timeout.code;
} on HttpException catch (httpEx) {
Realm.logger.log(Level.WARNING, "A HttpException occurred while executing $method $url: $httpEx");
Realm.logger.log(RealmLogLevel.warn, "HTTP Transport: HttpException executing $method $url: $httpEx");
responseRef.custom_status_code = _CustomErrorCode.unknownHttp.code;
} catch (ex) {
Realm.logger.log(Level.SEVERE, "A HttpException occurred while executing $method $url: $ex");
Realm.logger.log(RealmLogLevel.error, "HTTP Transport: Exception executing $method $url: $ex");
responseRef.custom_status_code = _CustomErrorCode.unknown.code;
} finally {
_realmLib.realm_http_transport_complete_request(request_context, response_pointer);
Expand Down
4 changes: 4 additions & 0 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ Future<void> setupTests(List<String>? args) async {
Realm.logger = Logger.detached('test run')
..level = Level.ALL
..onRecord.listen((record) {
if (record.level.value >= RealmLogLevel.warn.value) {
print('${record.time} ${record.level.name}: ${record.message}');
}

testing.printOnFailure('${record.time} ${record.level.name}: ${record.message}');
});

Expand Down

0 comments on commit 9da1d1e

Please sign in to comment.