HttpTransport class

Transport that sends log events to an HTTP endpoint as JSON.

By default the payload is:

{
  "level": "info",
  "message": <message.toString() or the object itself if Map/List>,
  "timestamp": "2024-...",
  "error": "...",      // omitted when null
  "stackTrace": "...", // omitted when null
  "context": "..."     // omitted when null
}

Provide serializer to send a fully custom payload:

HttpTransport(
  'https://example.com/logs',
  serializer: (e) => {'ts': e.timestamp.millisecondsSinceEpoch, 'msg': e.message},
)

config keys:

  • headers (MapString, String): additional request headers.
  • proxy (String): proxy address, e.g. "localhost:8888".
  • timeout (int): request timeout in milliseconds.
Inheritance
Available extensions

Constructors

HttpTransport(String endpoint, {LogLevel level = LogLevel.info, Map<String, dynamic> config = const {}, LogEventSerializer? serializer})

Properties

config Map<String, dynamic>
Arbitrary key/value options passed to the transport at construction time.
finalinherited
endpoint String
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
final
level LogLevel
Minimum severity level this transport will handle.
finalinherited
proxy String?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serializer LogEventSerializer?
Optional custom serializer. When set, its return value is JSON-encoded and sent as the request body, replacing the default payload.
final
timeout int?
final

Methods

emitLog(LogEvent event) Future<void>
Performs the actual delivery of event to the transport's destination.
override
log(LogEvent event) Future<void>
Delivers event to the destination if event.level >= this.level.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withBuffer({int maxSize = 100, Duration? flushInterval}) BufferedTransport

Available on Transport, provided by the BufferedTransportExtension extension

Wraps this transport in a BufferedTransport.

Operators

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