DatadogLogStrategy class
A LogStrategy implementation that sends logs to Datadog using the v2 API.
This strategy provides integration with Datadog's logging service, allowing for centralized log management and analysis. It supports structured logging with metadata and context information.
Features:
- HTTP-based log transmission to Datadog v2 API
- Gzip compression for reduced network overhead
- Structured logging with metadata and context
- Batch processing for efficiency
- Error handling and retry logic
- Performance monitoring
Example:
var datadogStrategy = DatadogLogStrategy(
apiKey: 'your-datadog-api-key',
service: 'my-app',
env: 'production',
enableCompression: true, // Default: true
);
await logger.initialize(strategies: [datadogStrategy]);
logger.log("Application started.", context: {'userId': 123});
- Inheritance
-
- Object
- LogStrategy
- HttpLogStrategy
- DatadogLogStrategy
Constructors
-
DatadogLogStrategy({required String apiKey, required String service, required String env, String? host, String? source, String? tags, String datadogUrl = 'https://http-intake.logs.datadoghq.com/api/v2/logs', bool enableCompression = true, 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}) - Constructs a DatadogLogStrategy.
Properties
- apiKey → String
-
Your Datadog API key.
final
- batchSize → int
-
Number of log entries to accumulate before sending a batch.
finalinherited
- batchTimeout → Duration
-
Maximum time to wait before sending an incomplete batch.
finalinherited
- datadogUrl → String
-
Datadog API URL (defaults to v2 endpoint for US region).
final
- enableCompression → bool
-
Enable gzip compression for reduced network overhead.
final
- endpoint → String
-
The HTTP endpoint URL to send log batches to.
no setteroverride
- env → String
-
Environment name (e.g., 'production', 'staging').
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
HTTP headers to include with each batch request.
no setteroverride
- host → String?
-
Host name (optional, defaults to platform hostname).
final
- 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.
finalinherited
- performanceOperationName → String
-
The performance monitor operation name for batch sends.
no setterinherited
- retryDelay → Duration
-
Base delay between retry attempts (multiplied by attempt number).
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- service → String
-
Service name for the logs.
final
- source → String?
-
Source name (optional, defaults to 'dart').
final
- strategyName → String
-
The name of this strategy, used in log messages for debugging.
no setteroverride
-
supportedEvents
↔ List<
LogEvent> ? -
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited
-
Additional tags as comma-separated string (e.g., 'team:mobile,version:1.0.0').
final
- useIsolate → bool
-
Whether this strategy should use isolates for heavy operations.
finalinherited
Methods
-
dispose(
) → void -
Disposes the strategy and cleans up resources.
inherited
-
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.
inherited
-
formatLogEntry(
LogEntry entry) → Map< String, dynamic> -
Formats a single LogEntry into a map suitable for the target API.
override
-
handleLog(
LogEntry entry) → Future< void> -
Main log handler - override this single method for uniform handling of all log levels.
inherited
-
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< batch) → Future<String, dynamic> >({List< int> body, Map<String, String> extraHeaders})> -
Prepares the batch body bytes for sending.
override
-
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