LoggingInterceptor class

Clean logging interceptor with redaction support

Features:

  • Configurable log levels
  • Sensitive data redaction
  • Request ID tracking for distributed debugging
  • Clean, formatted output
  • Custom log function support

Example:

LoggingInterceptor(
  level: LogLevel.body,
  redactHeaders: ['authorization', 'cookie', 'x-api-key'],
  redactFields: ['password', 'token', 'ssn', 'credit_card'],
  logPrint: (message) => debugPrint(message), // Custom logger
);
Inheritance

Constructors

LoggingInterceptor({LogLevel level = LogLevel.body, List<String> redactHeaders = const ['authorization', 'cookie', 'x-api-key', 'api-key'], List<String> redactFields = const ['password', 'token', 'access_token', 'refresh_token', 'ssn', 'credit_card', 'cvv'], void logPrint(String message)?})

Properties

hashCode int
The hash code for this object.
no setterinherited
level LogLevel
Logging level
final
logPrint → void Function(String message)?
Custom log function (defaults to print)
final
redactFields List<String>
JSON fields to redact (case-insensitive)
final
redactHeaders List<String>
Headers to redact (case-insensitive)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(DioException err, ErrorInterceptorHandler handler) → void
Called when an exception was occurred during the request.
override
onRequest(RequestOptions options, RequestInterceptorHandler handler) → void
Called when the request is about to be sent.
override
onResponse(Response response, ResponseInterceptorHandler handler) → void
Called when the response is about to be resolved.
override
toString() String
A string representation of this object.
inherited

Operators

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