Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/2 split http #6

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,50 @@
- **Cross-Platform Support**: With `dart_seq`, you can enjoy consistent logging capabilities across all Dart-supported platforms. It leverages the inherent cross-platform capabilities of Dart, making it easy to adopt and utilize in your applications, regardless of the target platform.
- **Customizable Seq Client and Caching Implementations**: `dart_seq` provides an intuitive and flexible interface to customize your Seq client and caching implementations. This enables you to tailor the logging behavior to your specific requirements and preferences, adapting the library to various use cases and scenarios in your Dart applications.
- **Batch Sending of Events**: `dart_seq` optimizes log transmission by sending events to Seq in batches. This helps minimize network overhead and improves overall logging performance, especially in high-traffic scenarios.
- **Automatic Retry Mechanism**: The library automatically retries failed requests to the Seq server, except in the case of 429 (Too Many Requests) responses. This built-in resilience ensures that log entries are reliably delivered, even in the face of intermittent network connectivity or temporary server unavailability.
- **Minimum Log Level Enforcement**: `dart_seq` keeps track of the server-side configured minimum log level and discards events that fall below this threshold. This feature helps reduce unnecessary log entries and ensures that only relevant and significant events are forwarded to the Seq server.

With `dart_seq`, logging in your Dart applications becomes a breeze, ensuring that your logs are efficiently delivered to Seq servers across multiple platforms.
The library's batch sending, automatic retry, and minimum log level enforcement features enhance the logging experience and provide robustness and flexibility to your logging infrastructure.

## Getting Started

To start using `dart_seq` in your Dart application, follow these steps:
To start using `dart_seq` in your Dart/Flutter application, follow these steps:

1. Install the library using `dart pub add dart_seq`
2. Import the package: `import 'package:dart_seq/dart_seq.dart';`
3. Instantiate the `SeqLogger` class
4. Start logging
1. Install this library and the HTTP client: `dart pub add dart_seq dart_seq_http_client`
2. Instantiate client, cache and logger (see usage below)
3. Enjoy!

## Usage

> **Note**
> This library provides just the interfaces and scaffolding.
> To actually log events, you need to use a client implementation like
> [`dart_seq_http_client`](https://pub.dev/packages/dart_seq_http_client).

After the installation, you can use the library like this:

```dart
import 'package:dart_seq/dart_seq.dart';
import 'package:dart_seq_http_client/dart_seq_http_client.dart';

Future<void> main() async {
// configure your logger
final logger = SeqLogger.http(
// Use the HTTP client implementation to create a logger
final logger = SeqHttpLogger.create(
host: 'http://localhost:5341',
globalContext: {
'Environment': Platform.environment,
'App': 'Example',
},
);

// add log events
await logger.log(SeqLogLevel.information, 'test, dart: {Dart}', null, {
'Dart': Platform.version,
});
// Log a message
await logger.log(
SeqLogLevel.information,
'test, logged at: {Timestamp}',
null,
{
'Timestamp': DateTime.now().toUtc().toIso8601String(),
},
);

// don't forget to flush your logs at the end!
// Flush the logger to ensure all messages are sent
await logger.flush();
}
```
Expand Down
10 changes: 0 additions & 10 deletions example/docker-compose.yml

This file was deleted.

21 changes: 0 additions & 21 deletions example/main.dart

This file was deleted.

2 changes: 0 additions & 2 deletions lib/dart_seq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export 'src/seq_client.dart';
export 'src/seq_client_exception.dart';
export 'src/seq_context.dart';
export 'src/seq_event.dart';
export 'src/seq_http_client.dart';
export 'src/seq_in_memory_cache.dart';
export 'src/seq_log_level.dart';
export 'src/seq_logger.dart';
export 'src/seq_response.dart';
137 changes: 0 additions & 137 deletions lib/src/seq_http_client.dart

This file was deleted.

38 changes: 0 additions & 38 deletions lib/src/seq_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,6 @@ class SeqLogger {
this.autoFlush = true,
}) : assert(backlogLimit >= 0, 'backlogLimit must be >= 0');

/// Creates a new instance of [SeqLogger] that logs to a Seq server over HTTP.
///
/// This method is a factory for creating a new instance of [SeqLogger] that
/// logs to a Seq server over HTTP using the [SeqHttpClient].
///
/// By default, a new instance of [SeqInMemoryCache] is used for caching the
/// events. If you want to use a different cache, you can pass it as the
/// [cache] parameter.
factory SeqLogger.http({
required String host,
String? apiKey,
int maxRetries = 5,
SeqCache? cache,
int backlogLimit = 50,
SeqContext? globalContext,
String? minimumLogLevel,
bool autoFlush = true,
Duration Function(int tries)? httpBackoff,
}) {
final httpClient = SeqHttpClient(
host: host,
apiKey: apiKey,
maxRetries: maxRetries,
backoff: httpBackoff,
);

final actualCache = cache ?? SeqInMemoryCache();

return SeqLogger(
client: httpClient,
cache: actualCache,
backlogLimit: backlogLimit,
globalContext: globalContext,
minimumLogLevel: minimumLogLevel,
autoFlush: autoFlush,
);
}

/// Compares two log levels.
static int compareLevels(String? a, String? b) {
if (a == null && b == null) {
Expand Down
19 changes: 0 additions & 19 deletions lib/src/seq_response.dart

This file was deleted.

3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ screenshots:
environment:
sdk: '^3.0.0'

dependencies:
http: '>=0.13.3 <2.0.0'

dev_dependencies:
build_runner: ^2.4.8
mockito: ^5.4.4
Expand Down
17 changes: 0 additions & 17 deletions test/seq_response_test.dart

This file was deleted.