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
eventto the transport's destination.override -
log(
LogEvent event) → Future< void> -
Delivers
eventto the destination ifevent.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. -
withSampling(
{required double sampleRate, List< LogLevel> levels = const [], Random? random}) → SamplingTransport -
Available on Transport, provided by the SamplingTransportExtension extension
Wraps this transport in a SamplingTransport.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited