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',
this.deviceHeaderName = 'X-device-id',
})
correlationalHeaderNameanddeviceHeaderNamemust be non-empty.- Default
deviceIdentifierlives onSinkSeq; when the request includes theX-device-idheader (or the name set indeviceHeaderName), that value becomes the eventDeviceIdentifier. Without the header,SinkSeq.deviceIdentifieris used.
Templates and properties
Message templates use {property} placeholders aligned with StructureLogger (not {@property}).
- REQUEST:
REQUEST: {method} {path} {correlationalSeqID} {headers} - RESPONSE:
RESPONSE: {statusCode} {path} {correlationalSeqID} {headers} {elapsedTime} - ERROR:
ERROR: {statusCode} {path} {correlationalSeqID} {message} {headers} {elapsedTime}
Each request query parameter is emitted as a top-level queryParam.<name> property (e.g. queryParam.page=1), enabling filters in CLEF Viewer.
JWT tokens in headers, query params, and bodies are obfuscated in logs (eyJhbG...***); original Dio request headers are not modified.
Request/response bodies are not part of @mt; they are emitted as structured properties (data, errorData) for search and inspection in the viewer.
See the package source for the full property map (event_type, elapsedTime, etc.).