---
title: "Logging Voice AI Calls | Micdrop"
description: "Log each call with levels and structured fields: a readable console output, MICDROP_LOG, or your own pino, winston or Fastify logger, with the call id on every line."
url: "https://micdrop.dev/docs/server/logging"
---

# Logging Voice AI Calls

Micdrop logs every call with levels and structured fields. Each line carries the id of the call and the component that wrote it, the STT, the agent or the transport, so the lines of concurrent calls stay apart. The logs go to the console in a compact form, or to the logger your application already runs.

By default only warnings and errors are written, so a call costs nothing in logs until you ask for more.

## Turn the logs on

Set `MICDROP_LOG` to a level when starting the server:

```bash
MICDROP_LOG=info node server.js
```

Or pass `logger` in the config of the call:

```typescript
const server = new MicdropServer(socket, {
  stt,
  agent,
  tts,
  logger: 'info',
})
```

`logger: true` stands for `'info'` and `logger: false` silences the call, warnings included.

## Levels

Level

What it shows

`trace`

Every audio chunk and every message of the providers, to debug a stream

`debug`

Each step of the components: connections, requests, transcripts, cancels

`info`

The call turn by turn: start, user speech, transcript, answer, tool calls, handoffs, reconnections, the latency of each turn and the summary of the call

`warn`

Something went wrong and the call carries on: a provider error, a fallback, a slow tool

`error`

Something failed: an answer, a tool, a connection out of retries

`silent`

Nothing

A level shows the lines of its own level and of the levels below it in this table. `info` reads like a transcript of the call:

```
12:04:30.912 INFO  4f2a9c1e server Call started transport=WebSocketTransport stt=DeepgramSTT agent=OpenaiAgent tts=CartesiaTTS
12:04:31.270 INFO  4f2a9c1e server User started speaking
12:04:32.104 INFO  4f2a9c1e server User stopped speaking
12:04:32.161 INFO  4f2a9c1e server User text="What time do you open?"
12:04:32.702 INFO  4f2a9c1e server Assistant text="We open at nine."
12:04:33.380 INFO  4f2a9c1e server Turn ended turn=2 trigger=user latencyMs=598 sttMs=57 llmMs=312 ttsMs=229
12:04:41.015 INFO  4f2a9c1e server Call ended code=1005 durationS=10 turns=2 medianLatencyMs=598
```

Colors come on when the output is a terminal. `NO_COLOR` turns them off and `FORCE_COLOR` forces them.

From `info` up, the lines carry what the user and the assistant say. Keep production logs at `warn`, or filter the `text` field in a function logger, when your logs are not cleared to hold transcripts.

## Use your own logger

`logger` takes the logger of your application as it is. Micdrop calls it with the argument order it expects:

Logger

How Micdrop calls it

pino, bunyan, the `request.log` of Fastify

`logger.info(fields, message)`

winston, consola, any object with `debug`, `info`, `warn` and `error`

`logger.info(message, fields)`

`console`

The compact console output above

A function

`fn(entry)`, with `level`, `message`, `fields` and `time`

A logger that knows its level, pino and winston among them, decides alone what it keeps: Micdrop asks it before building a line, so a `trace` it drops costs nothing. The level you pass applies to the other kinds, `info` when you give none.

With Fastify, the request logger adds the request id to every line of the call:

```typescript
fastify.get('/call', { websocket: true }, (socket, request) => {
  new MicdropServer(socket, { stt, agent, tts, logger: request.log })
})
```

A function receives every line kept, to send it anywhere or drop the fields you keep out of your logs:

```typescript
import type { LogEntry } from '@micdrop/server'

const server = new MicdropServer(socket, {
  stt,
  agent,
  tts,
  logger: {
    level: 'debug',
    output: ({ level, message, fields }: LogEntry) => {
      const { text, ...rest } = fields
      myLogger.log(level, message, rest)
    },
  },
})
```

## The fields of a line

Every line of a call carries:

*   `callId`, a random id of 8 characters, or the one you pass as `callId` in the config, the id of the call in your database for instance
*   `component`: `server`, `transport`, `turns`, `stt`, `agent`, `tts`, `realtime`, `pipeline`, `classifier` or `recorder`
*   `provider`, the class of the component, such as `DeepgramSTT`

The server hands the logger of the call to every component it runs, the agents a handoff brings in and the providers of a `FallbackSTT`, `FallbackTTS` or `FallbackAgent` included. `server.logger` is that logger, to write the lines of your application with the same id:

```typescript
const server = new MicdropServer(socket, { stt, agent, tts, callId: user.id })
server.logger.info('Call authorized', { plan: user.plan })
```

## The default logger

A call without `logger` logs through the default logger, the console at the level `MICDROP_LOG` gives, `warn` otherwise. `setDefaultLogger()` replaces it for the whole process: the calls started afterwards and the components running outside a call log through the new one.

```typescript
import { setDefaultLogger } from '@micdrop/server'
import pino from 'pino'

setDefaultLogger(pino({ level: 'info' }))
```

## Log from a custom component

A custom STT, TTS, agent or classifier logs through `this.logger`, already scoped with the call and the component:

```typescript
class MySTT extends STT {
  transcribe(audioStream: Readable) {
    this.logger.debug('Transcribing')
    audioStream.on('data', (chunk: Buffer) => {
      this.logger.trace('Audio chunk', { bytes: chunk.byteLength })
    })
  }
}
```

Keep the data out of the message and in the fields, so a log backend can filter on it. When a field is costly to build, check the level first with `this.logger.isEnabled('trace')`.

A component used without a server, a classifier on its own for instance, takes a logger with `attachLogger()`:

```typescript
import { Logger } from '@micdrop/server'

classifier.attachLogger(new Logger({ level: 'debug' }))
```

## Correlate with OpenTelemetry

When [`traceCall()`](/docs/server/opentelemetry) traces a call, it adds `trace_id`, `span_id` and `trace_flags` to every line of the call, so a backend such as Grafana or Datadog links each line to the trace. The ids are those of the call span, open for the whole call. `correlateLogs: false` leaves the lines alone.

## On the client

The client logs the same way, with `component` set to `client`, `transport`, `recorder`, `vad`, `mic` or `speaker`. It takes the same `logger` option, and `debugLog: true` stands for `logger: 'debug'`:

```typescript
Micdrop.start({ url: 'ws://localhost:8081', logger: 'info' })
```

In a browser, `localStorage.setItem('MICDROP_LOG', 'debug')` turns the logs on for a page already deployed, without changing its code. Reload the page afterwards.

## Coming from `Logger`

Before levels, a `Logger` was set on each component by hand. That still works, and the components set by hand keep their logger rather than the one of the call:

Before

Now

`server.logger = new Logger('Server')`, and the same on the agent, STT and TTS

`logger: 'debug'` in the config

`this.log('Connected', details)` in a custom component

`this.logger.debug('Connected', { details })`

`{ log: (...message) => request.log.debug(message) }`

`logger: request.log`

Each of these older forms writes one warning per process, through the default logger, saying what replaces it. `new Logger(name)` keeps every line from `debug` up, as it printed everything before, the audio chunks aside. `this.log()` writes at `debug` level, a first string becoming the message and the objects after it the fields.
