HttpLogStrategy class abstract

Base class for HTTP-based logging strategies.

Provides shared functionality for strategies that send logs to remote HTTP endpoints, including:

  • Batch processing with configurable size and timeout
  • Retry logic with exponential backoff
  • HttpClient management
  • Proper resource disposal

Subclasses only need to implement formatLogEntry, endpoint, headers, and strategyName to create a fully functional HTTP logging strategy.

Example:

class MyHttpStrategy extends HttpLogStrategy {
  MyHttpStrategy({required this.apiKey})
      : super(batchSize: 100, batchTimeout: Duration(seconds: 5));

  final String apiKey;

  @override
  String get strategyName => 'MyHttpStrategy';
  @override
  String get endpoint => 'https://api.example.com/logs';
  @override
  Map<String, String> get headers => {'Authorization': 'Bearer $apiKey'};
  @override
  Map<String, dynamic> formatLogEntry(LogEntry entry) => entry.toMap();
}
Inheritance
Implementers

Constructors

HttpLogStrategy({int batchSize = 100, Duration batchTimeout = const Duration(seconds: 5), int maxRetries = 3, Duration retryDelay = const Duration(seconds: 1), bool useIsolate = true, LogLevel logLevel = LogLevel.none, List<LogEvent>? supportedEvents})
Creates an HttpLogStrategy with the given configuration.

Properties

batchSize → int
Number of log entries to accumulate before sending a batch.
final
batchTimeout → Duration
Maximum time to wait before sending an incomplete batch.
final
endpoint → String
The HTTP endpoint URL to send log batches to.
no setter
hashCode → int
The hash code for this object.
no setterinherited
headers → Map<String, String>
HTTP headers to include with each batch request.
no setter
loggerLogLevel ↔ LogLevel
The log level set by the logger using this strategy. Used to determine if a message should be logged.
getter/setter pairinherited
logLevel ↔ LogLevel
The minimum log level that this strategy handles for logging.
getter/setter pairinherited
maxRetries → int
Maximum number of retry attempts for failed batch sends.
final
performanceOperationName → String
The performance monitor operation name for batch sends.
no setter
retryDelay → Duration
Base delay between retry attempts (multiplied by attempt number).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
strategyName → String
The name of this strategy, used in log messages for debugging.
no setter
supportedEvents ↔ List<LogEvent>?
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited
useIsolate → bool
Whether this strategy should use isolates for heavy operations.
finalinherited

Methods

dispose() → void
Disposes the strategy and cleans up resources.
error(LogEntry entry) → Future<void>
Logs an error.
inherited
fatal(LogEntry entry) → Future<void>
Logs a fatal error.
inherited
flush() → Future<void>
Forces sending of all pending logs.
formatLogEntry(LogEntry entry) → Map<String, dynamic>
Formats a single LogEntry into a map suitable for the target API.
handleLog(LogEntry entry) → Future<void>
Main log handler - override this single method for uniform handling of all log levels.
override
info(LogEntry entry) → Future<void>
Logs an info message.
inherited
log(LogEntry entry) → Future<void>
Logs a debug or general message.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepareBatchBody(List<Map<String, dynamic>> batch) → Future<({List<int> body, Map<String, String> extraHeaders})>
Prepares the batch body bytes for sending.
shouldLog({LogEvent? event}) → bool
Determines whether a log operation should proceed based on the event and log level.
inherited
toString() → String
Provides a string representation of the strategy including its type and log level.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited