Log to the console
Print every call's route, status, headers, bodies and error to the console during development.
logger writes one structured entry per call for production logs, and leaves
headers, query strings and bodies out. consoleLogger is for development: it
prints everything about a call to the console, as a group devtools can
expand. This page shows how to add it, what it prints, and how to tune it.
Add the console logger
Add consoleLogger to the client's plugins. This example turns it on only in
development, flags calls slower than a second, and redacts an extra body key:
import { } from "@monarcode/effetch";
import { } from "@monarcode/effetch/plugins";
declare const : boolean;
export class extends .<>()("Api", {
: "https://api.example.com",
: [
({
: ,
: "1 second",
: { : ["otp"] },
}),
],
}) {}Read the output
Each call prints a line, which opens a group with the details:
▸ GET /todos/:id 200 OK 35 ms 1.2 kB
▸ ✗ GET /todos 3.0 s → NetworkError: Failed to fetch
▸ ⚠ GET /reports/:id 200 OK 2.4 s (slow)
▾ ✗ POST /users/:id/roles 400 Bad Request 120 ms → InvalidRole: No such role
POST https://api.example.com/users/7/roles
request headers { accept: "application/json", authorization: "<redacted>" }
request body { role: "owner" }
response headers { "content-type": "application/json" }
response body { code: "INVALID_ROLE", message: "No such role" }
error InvalidRole { code: "INVALID_ROLE", message: "No such role" }It prints each call once it's over, with the error it ended with, after
statusErrors and decoding. Values are printed
as objects, so devtools can expand them.
Options
consoleLogger takes the following options:
| Option | Default | What it does |
|---|---|---|
enabled | true | false prints nothing, and keeps the plugin's type, so it can stay in the list in production. |
detail | "full" | "summary" prints the line alone; "headers" adds the URL, headers and error; "full" adds the bodies. |
only | "all" | "errors" prints failed calls only. |
collapsed | true | Whether groups start collapsed. false by default in React Native, where Metro's terminal drops collapsed groups. Node, Bun and Deno print them expanded. |
slow | false | A duration, such as "1 second": slower calls are flagged. |
maxBodyLength | 10_000 | Body text longer than this is cut. JSON within it is printed as an object. |
redact | { headers, query, body }: more names to redact, as strings (ignoring case, - and _) or regular expressions. false redacts nothing. | |
filter | (call) => boolean: prints only the calls it accepts. call has the route, the request, the response, the exit and the durationMs. | |
color | "auto" | "css" (browser devtools), "ansi" (terminals), or false. "auto" uses "css" where there's a document, else plain text. |
Change the output for one call
Calls can change detail, only, collapsed, slow and maxBodyLength, or
skip it with false:
import * as from "effect/Effect";
import { } from "@monarcode/effetch";
import { } from "@monarcode/effetch/plugins";
class extends .<>()("Api", {
: "https://api.example.com",
: [()],
}) {}
export const = .(function* () {
const = yield* ;
yield* .("/reports/export", {
: { : { : "summary" } },
});
yield* .("/health", { : { : false } });
});Redaction, bodies, platforms and timing
Expand the following sections for what consoleLogger redacts, which bodies
it reads, how it behaves on each platform, and when it runs:
It replaces these with <redacted>, matching names ignoring case, - and
_:
- headers in Effect's
Headers.CurrentRedactedNames(authorization,cookie,set-cookie,x-api-key),proxy-authorization,x-auth-token,x-access-token,x-refresh-token,x-session-token,x-csrf-token,x-xsrf-token,x-client-secretandx-amz-security-token; - keys in JSON and form bodies, at any depth:
token,accessToken,refreshToken,idToken,authToken,apiToken,sessionToken,csrfToken,xsrfToken,secret,clientSecret,apiSecret,apiKey,privateKey, and any name containingpassword; - query parameters with the same names,
key,sig,signatureand the signed-URL ones (X-Amz-Signature,X-Goog-Signature, …), values passed asRedacted, and credentials in the URL (https://user:password@…).
They're exact names rather than patterns, so fields such as total_tokens
stay visible. Plain-text bodies are printed as they are. A call's error is
printed as a copy of its fields, redacted like a body, without an
HttpError's text or a DecodeError's issue, which the response body
line shows. Defects are printed as they are.
- It only reads a response body that's text: JSON,
text/*other than event streams, XML or a form, up to 1 MB. Effetch has read it already to check the status or decode it, and Effect caches it. A call withoutoutputreturns the response itself, so its body isn't read, and stays yours to stream. Neither is an interrupted call's. - It writes through Effect's
Console, so you can provide another one, withconsole.logand groups only. React Native turnsconsole.errorinto an error screen. - In React Native, groups start expanded: Metro's terminal silently drops
console.groupCollapsedand everything logged inside it. React Native is detected bynavigator.product, which it sets to"ReactNative". - It runs when the call is over, so where it sits in the plugin list doesn't
matter: a retried call is one entry, and its duration covers every
attempt. The size comes from
content-length, or from the body when it's read. - When a plugin fails on a response, such as an auth plugin on a 401, that response is shown with the plugin's error.
slowthat isn't a duration throws when the plugin is made.- The request shown is the one that was sent, after plugins such as
bearerchanged it. When no response came back, it's the one the call built, before plugins ran.
What's next
- Built-in plugins: compare
consoleLoggerwithloggerfor production logs. - Change plugins for one call: skip or adjust any plugin on a single call.
- Write a plugin: build your own logging or metrics
on the
onExithook thatconsoleLoggeruses.