Skip to content

Commit

Permalink
feat: add logging to functions_client
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Oct 3, 2024
1 parent 7e67afc commit 729f29a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/functions_client/lib/src/functions_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'dart:typed_data';

import 'package:functions_client/src/constants.dart';
import 'package:functions_client/src/types.dart';
import 'package:functions_client/src/version.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart' show MultipartRequest;
import 'package:logging/logging.dart';
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart';

class FunctionsClient {
Expand All @@ -13,6 +15,7 @@ class FunctionsClient {
final http.Client? _httpClient;
final YAJsonIsolate _isolate;
final bool _hasCustomIsolate;
final _log = Logger("supabase.functions");

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

/// Getter for the headers
Map<String, String> get headers {
Expand Down Expand Up @@ -129,6 +134,8 @@ class FunctionsClient {
request.headers[key] = value;
});

_log.finer('Request: ${request.method} ${request.url} ${request.headers}');

final response = await (_httpClient?.send(request) ?? request.send());
final responseType = (response.headers['Content-Type'] ??
response.headers['content-type'] ??
Expand Down Expand Up @@ -167,6 +174,7 @@ class FunctionsClient {
///
/// Does nothing if you pass your own isolate
Future<void> dispose() async {
_log.fine("Dispose FunctionsClient");
if (!_hasCustomIsolate) {
return _isolate.dispose();
}
Expand Down
1 change: 1 addition & 0 deletions packages/functions_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ environment:

dependencies:
http: '>=0.13.4 <2.0.0'
logging: ^1.2.0
yet_another_json_isolate: 2.0.2

dev_dependencies:
Expand Down

0 comments on commit 729f29a

Please sign in to comment.