Skip to content

Commit 729f29a

Browse files
committed
feat: add logging to functions_client
1 parent 7e67afc commit 729f29a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/functions_client/lib/src/functions_client.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import 'dart:typed_data';
33

44
import 'package:functions_client/src/constants.dart';
55
import 'package:functions_client/src/types.dart';
6+
import 'package:functions_client/src/version.dart';
67
import 'package:http/http.dart' as http;
78
import 'package:http/http.dart' show MultipartRequest;
9+
import 'package:logging/logging.dart';
810
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart';
911

1012
class FunctionsClient {
@@ -13,6 +15,7 @@ class FunctionsClient {
1315
final http.Client? _httpClient;
1416
final YAJsonIsolate _isolate;
1517
final bool _hasCustomIsolate;
18+
final _log = Logger("supabase.functions");
1619

1720
/// In case you don't provide your own isolate, call [dispose] when you're done
1821
FunctionsClient(
@@ -24,7 +27,9 @@ class FunctionsClient {
2427
_headers = {...Constants.defaultHeaders, ...headers},
2528
_isolate = isolate ?? (YAJsonIsolate()..initialize()),
2629
_hasCustomIsolate = isolate != null,
27-
_httpClient = httpClient;
30+
_httpClient = httpClient {
31+
_log.config("Initialize FunctionsClient v$version");
32+
}
2833

2934
/// Getter for the headers
3035
Map<String, String> get headers {
@@ -129,6 +134,8 @@ class FunctionsClient {
129134
request.headers[key] = value;
130135
});
131136

137+
_log.finer('Request: ${request.method} ${request.url} ${request.headers}');
138+
132139
final response = await (_httpClient?.send(request) ?? request.send());
133140
final responseType = (response.headers['Content-Type'] ??
134141
response.headers['content-type'] ??
@@ -167,6 +174,7 @@ class FunctionsClient {
167174
///
168175
/// Does nothing if you pass your own isolate
169176
Future<void> dispose() async {
177+
_log.fine("Dispose FunctionsClient");
170178
if (!_hasCustomIsolate) {
171179
return _isolate.dispose();
172180
}

packages/functions_client/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ environment:
1010

1111
dependencies:
1212
http: '>=0.13.4 <2.0.0'
13+
logging: ^1.2.0
1314
yet_another_json_isolate: 2.0.2
1415

1516
dev_dependencies:

0 commit comments

Comments
 (0)