Skip to content

Logging

Arun Prakash edited this page Oct 25, 2026 · 1 revision

Logging

LoggingMiddleware writes one line per request to a sink of your choice. Credentials never reach the log.

final client = WordpressClient.forSite(
  siteUrl: siteUrl,
  bootstrapper: (b) => b.withMiddleware(LoggingMiddleware(sink: myLogger.info)).build(),
);

The output looks like this:

GET https://example.com/wp-json/wp/v2/posts?per_page=5 -> 200 in 143 ms
POST https://example.com/wp-json/wp/v2/posts -> ERR connectionFailed in 12 ms
Option Default
sink print Receives each formatted line
logRequests false Also log when a request starts
logHeaders false Request and response headers
logBodies false Bodies, cut at maxBodyLength (500)
redactedHeaders authorization, cookie, set-cookie, x-api-key, proxy-authorization Values shown as ***
redactedQueryKeys password, token, key, secret Values shown as ***

Transport failures (timeouts, connection errors, cancellations) reach onResponse too, with a negative code, so they are logged as well, as ERR <RequestErrorType>. The duration is the full round trip including retries; with retries the line shows the attempt count.

For raw network traces use a Dio interceptor instead (b.withDioInterceptor(LogInterceptor())), and for verbose library logging b.withDebugMode(true). See also Events and Statistics.

Clone this wiki locally