Dio HTTP logging
Use DioLoggingInterceptor to emit structured Log Events for HTTP requests, responses and errors. It delegates to a pre-configured StructureLogger (and its sinks such as SinkSeq).
Setup
import 'package:dio/dio.dart';
import 'package:structured_logger/structured_logger.dart';
import 'package:structured_logger_dio_interceptor/structured_logger_dio_interceptor.dart';
final logger = StructureLogger()
..addSink(SinkSeq(
'https://your-seq.example.com',
apiKey: 'your-api-key',
deviceIdentifier: 'my-app',
));
final dio = Dio()..interceptors.add(DioLoggingInterceptor(logger));
Behavior
onRequest: generates correlational UUID (default headerX-Request-Seq-Id), setsX-Request-Start-Time, emitsREQUESTevent.onResponse: emitsRESPONSEwithstatusCode,elapsedTime(ms), headers, data.onError: emitsON_ERROR(level error) with optional status and error data.
All events go through your registered sinks — no direct HTTP from the interceptor.
Constructor
DioLoggingInterceptor(
this._logger, {
this.correlationalHeaderName = 'X-Request-Seq-Id',
})
correlationalHeaderNamemust be non-empty (asserts otherwise).deviceIdentifierlives onSinkSeq, not here.
Templates (example)
The emitted @mt values follow legacy semantics for easy querying:
- REQUEST:
REQUEST: {@method} {@path} ... - RESPONSE / ERROR analogous.
See the package source for exact templates and data keys (event_type, elapsedTime, etc.).