Skip to content

Commit

Permalink
More documentation; reduced public API surface of SeqHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Mar 20, 2024
1 parent 87eff7f commit 33b652c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Unreleased

* More documentation
* Made methods in `SeqHttpClient` private:
* `collapseEvents`
* `sendRequest`
* `handleResponse`

## 1.0.0

* First stable release 🎉
Expand Down
6 changes: 6 additions & 0 deletions lib/src/seq_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class SeqEvent {
this.context,
);

/// Creates an event from the given [map]. The map should be compatible with
/// the GELF logging format. The timestamp is parsed from the map, and the
/// message, message template, level, exception, and id are read from the map
/// as strings. The renderings are read as a map of strings, and the context
/// is read as a map of strings to dynamic.
/// If the map does not contain a timestamp, the current time is used.
factory SeqEvent.fromMap(Map<String, dynamic> map) {
DateTime? timestamp;
String? message;
Expand Down
13 changes: 7 additions & 6 deletions lib/src/seq_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:dart_seq/dart_seq.dart';
import 'package:http/http.dart' as http;

/// Calculates a linearly increasing duration to based on the number of [tries].
Duration linearBackoff(int tries) => Duration(milliseconds: tries * 100);

/// A HTTP ingestion client for Seq. Implements the [SeqClient] interface.
Expand Down Expand Up @@ -36,7 +37,7 @@ class SeqHttpClient implements SeqClient {

@override
Future<void> sendEvents(List<SeqEvent> events) async {
final body = collapseEvents(events);
final body = _collapseEvents(events);
if (body.isEmpty) {
SeqLogger.diagnosticLog(SeqLogLevel.verbose, 'No events to send.');

Expand All @@ -45,18 +46,18 @@ class SeqHttpClient implements SeqClient {

http.Response response;
try {
response = await sendRequest(body);
response = await _sendRequest(body);
} catch (e, stack) {
throw SeqClientException('Failed to send request', e, stack);
}

await handleResponse(response);
await _handleResponse(response);
}

String collapseEvents(List<SeqEvent> events) =>
String _collapseEvents(List<SeqEvent> events) =>
events.reversed.map(jsonEncode).join('\n');

Future<http.Response> sendRequest(String body) async {
Future<http.Response> _sendRequest(String body) async {
http.Response? response;
Exception? lastException;

Expand Down Expand Up @@ -94,7 +95,7 @@ class SeqHttpClient implements SeqClient {
return response!;
}

Future<void> handleResponse(http.Response response) async {
Future<void> _handleResponse(http.Response response) async {
final json = jsonDecode(response.body);
if (json is! Map<String, dynamic>) {
throw SeqClientException('The response body was not a JSON object');
Expand Down

0 comments on commit 33b652c

Please sign in to comment.