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]);
await logger.log("Application started.", context: {'userId': 123});
- Inheritance
-
- Object
- LogStrategy
- 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), LogLevel logLevel = LogLevel.none, List<
LogEvent> ? supportedEvents}) - Constructs a DatadogLogStrategy.
Properties
- apiKey → String
-
final
- batchSize → int
-
final
- batchTimeout → Duration
-
final
- datadogUrl → String
-
final
- enableCompression → bool
-
final
- env → String
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String?
-
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
-
final
- retryDelay → Duration
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- service → String
-
final
- source → String?
-
final
-
supportedEvents
↔ List<
LogEvent> ? -
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited
-
final
Methods
-
dispose(
) → void - Disposes the strategy and cleans up resources
-
error(
LogEntry entry) → Future< void> -
Logs an error to Datadog
override
-
fatal(
LogEntry entry) → Future< void> -
Logs a fatal error to Datadog
override
-
flush(
) → Future< void> - Forces sending of all pending logs
-
info(
LogEntry entry) → Future< void> -
Logs an info message to Datadog
override
-
log(
LogEntry entry) → Future< void> -
Logs a message or event to Datadog
override
-
logError(
dynamic error, StackTrace? stackTrace, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging errors (for backward compatibility).
inherited
-
logMessage(
dynamic message, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging messages (for backward compatibility).
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
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