I need to Log a full requisition Body, one single time on each req that my system does. I’am using StringBuffer, Dio and LogInterceptor.
What happens:
My log is printing the building of the body, not the full body’s req.
CODE:
if (kDebugMode) {
StringBuffer logObject = StringBuffer();
dio.interceptors.add(
LogInterceptor(
requestBody: true,
responseBody: true,
requestHeader: true,
responseHeader: true,
error: true,
logPrint: (Object object) {
logObject.writeln(object);
djLogger.debug(
content: "Value Custom DIO: ",
value: logObject,
);
},
),
);
}
What I’ve tried
I tried to log the logObject outside the dio.interceptors.add()
, but the result of my log was Null
.
2
Answers
You can simply use a
log
method for get full req body printed.Well I hope you are using a common network class to access the same dio instance for all your network calls. If yes, then you can try the following:
So, let’s say you initialized a Dio object.
You can add log or any type of interceptors to that dio object. For adding only one inteceptor, you can do the following:
Here is the logging interceptor class:
Hope this helps