LoggingInterceptor class
Dio interceptor that emits human-readable log lines through a user-supplied callback.
Lucky Dart has no built-in logging dependency. Instead, you wire
LoggingInterceptor to your own logger by providing the onLog callback.
The callback receives a message string, an optional severity level
('debug', 'info', or 'error'), and an optional context tag
('Lucky').
The interceptor is only added to Dio when the connector's enableLogging
flag is true and an onLog callback is provided.
Logging can be suppressed on a per-request basis by setting
extra['logRequest'] or extra['logResponse'] to false in the
request's Options.extra map.
LoggingInterceptor(
onLog: ({required message, level, context}) {
// Route to your preferred logger, e.g. `print`, `logger`, or `talker`.
print('[$level] $message');
},
);
Constructors
- LoggingInterceptor({required LuckyLogCallback onLog})
-
Creates a LoggingInterceptor with the required
onLogcallback.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- onLog → LuckyLogCallback
-
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 -
Logs network-level errors (e.g. connection refused, timeout) at
'error'level, then forwards the error to the next handler. -
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void -
Logs outgoing request details unless
options.extra['logRequest']isfalse. -
onResponse(
Response response, ResponseInterceptorHandler handler) → void -
Logs the received response unless
requestOptions.extra['logResponse']isfalse. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited