Skip to Content
Plugins

Log to the console

Print every call's route, status, headers, bodies and error to the console during development.

While you develop, a failed call is easier to fix when you can see what was sent and what came back. 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 that devtools can expand. This page shows how to add it, how to read 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 summary line. With detail: "full", the default, that line opens a group with the call's URL, headers, bodies and error. Here's what Node prints for six calls, with slow: "1 second". The first five ran with detail: "summary", so only the last one opens a group. The fourth was interrupted by Effect.timeout, and the fifth died because its bearer token function threw:

GET /todos/:id  200 OK  18 ms  24 B
✗ GET /todos  2 ms  → NetworkError: fetch failed
⚠ GET /reports/:id  200 OK  1.2 s  8 B  (slow)
⊘ GET /slow/:id  1.0 s  interrupted  (slow)
✗ GET /broken  0 ms  → defect: Error: No token store
✗ POST /users/:id/roles  400 Bad Request  2 ms  48 B  → InvalidRole: No such role
  POST https://api.example.com/users/7/roles
  request headers  {
    'content-type': 'application/json',
    'content-length': '16',
    accept: 'application/json',
    authorization: '<redacted>',
    b3: '…',
    traceparent: '…'
  }
  request body     { role: 'owner' }
  response headers { 'content-length': '48', 'content-type': 'application/json' }
  response body    { code: 'INVALID_ROLE', message: 'No such role' }
  error            { _tag: 'InvalidRole', message: 'No such role', code: 'INVALID_ROLE' }

The summary line starts with a mark for how the call ended:

  • no mark: it succeeded in time;
  • ✗: it failed, and the line ends with the error. A call that died shows → defect: and the defect;
  • ⚠: it succeeded, but took at least as long as slow, and the line ends with (slow);
  • ⊘: it was interrupted, such as by Effect.timeout.

It prints each call after it's over, with the error it ended with, after statusErrors and decoding. Values are printed as objects, so devtools can expand them. In browser devtools, the group starts collapsed under its summary line. Node, as the output shows, prints it expanded. The b3 and traceparent headers are the tracing headers that Effect's HttpClient adds, with their IDs cut here.

Options

consoleLogger takes the following options:

OptionDefaultWhat it does
enabledtruefalse 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. An interrupted call isn't a failed one.
collapsedtrue, false in React NativeWhether groups start collapsed. Metro's terminal drops collapsed groups, so React Native defaults to false.
slowfalseA duration, such as "1 second". Calls that take at least this long are flagged.
maxBodyLength10_000Body text longer than this many characters is cut. A JSON body within it is printed as an object.
redactBuilt-in names (see Details){ headers, query, body }: more names to redact, as strings (ignoring case, - and _) or regular expressions. false redacts nothing.
filterNone: every call is printed(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 and React Native DevTools), "ansi" (terminals), or false. "auto" uses "css" where there's a document, else plain text.

Change the output for one call

A call can change detail, only, collapsed, slow and maxBodyLength, or skip the plugin 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:

What's next

On this page