# Centralize Node.js logs with Pino and Tailcove

Pino is the most common structured logger in the Node.js world. This guide connects it to Tailcove with the official transport, so your existing `logger.info()` calls start shipping without touching application code.

## 1. Create a source

In Tailcove, open **Sources**, click **New source** and choose **Node.js** as the platform. Copy the ingest token shown after creation, it is only displayed once, and store it as an environment variable:

```bash@macOS_/_Linux
export TAILCOVE_TOKEN=your-source-ingest-token
```

```powershell@Windows_(PowerShell)
$env:TAILCOVE_TOKEN = "your-source-ingest-token"
```

This lasts for the current terminal session. To keep it, add the `export` line to `~/.zshrc` (macOS) or
`~/.bashrc` (Linux), or on Windows run `setx TAILCOVE_TOKEN "…"` once and open a new terminal. In production, set
it wherever your app's environment lives: the service unit, container or deploy settings.

## 2. Install the client

```bash
npm install @tailcove/node pino
```

## 3. Point Pino at Tailcove

```ts
import pino from 'pino';

export const logger = pino({
    transport: {
        target: '@tailcove/node/pino',
        options: { token: process.env.TAILCOVE_TOKEN },
    },
});
```

Pino levels map onto Tailcove's: `trace` and `debug` become `debug`, `warn` becomes `warning`, and `fatal` becomes `critical`.

## 4. Log structured events

Pass an object first and a constant message second:

```ts
logger.info({ userId: 42, plan: 'pro' }, 'user signed up');
logger.error({ orderId: 99, reason: 'card_declined' }, 'payment failed');
```

Every key in the object becomes a context field you can search, for example `orderId:99` or `reason:card_declined`.

## Prefer no logging framework?

Use the client directly. It adds `hostname`, `pid` and `env` to every line, and lets you attach your own defaults:

```ts
import { Tailcove } from '@tailcove/node';

const tailcove = new Tailcove({
    token: process.env.TAILCOVE_TOKEN!,
    context: { service: 'checkout-api', region: 'eu-west-1' },
});

tailcove.info('user signed up', { userId: 42 });
```

Using Winston instead? Swap in `TailcoveTransport` from `@tailcove/node/winston`.

## Secrets stay in your process

From 0.2.0 the client masks passwords, tokens and keys before a line is queued, with the same rules Tailcove uses on the server. A field named `password` or `apiKey` becomes `[redacted]`, and so does the value after `token=` in a message. Pass `secretKeys: ['customer_ssn']` in the transport options to add your own names. The direct client also takes a `beforeSend` hook to change or drop lines; see [Secret masking](https://tailcove.dev/docs/sending-logs/node#secret-masking).

## 5. Verify it works

Open the source's **Live tail** in Tailcove and start your service. Your first lines should appear within a couple of seconds. Lines are sent in batches of 50 or every 2 seconds, whichever comes first, so a single quiet line can take up to 2 seconds to show.

## 6. Shut down cleanly

The client flushes its buffer automatically on `beforeExit` and `SIGTERM`, so a deploy or container stop does not drop the last batch. If you manage shutdown yourself, disable that and flush at the right point:

```ts
const tailcove = new Tailcove({
    token: process.env.TAILCOVE_TOKEN!,
    flushOnShutdown: false,
});

process.on('SIGTERM', async () => {
    await server.close();
    await tailcove.shutdown();
    process.exit(0);
});
```

## Handling delivery failures

Delivery failures never throw into your app. Pass an `onError` callback if you want to know about them:

```ts
new Tailcove({
    token: process.env.TAILCOVE_TOKEN!,
    onError: (error) => console.warn('tailcove delivery failed', error),
});
```

## Next steps

- [Search your logs](https://tailcove.dev/docs/query-language) by any field you logged.
- [Track frontend errors](https://tailcove.dev/guides/react-error-tracking) from the browser side of the same app.
- Full option list in the [Node.js reference](https://tailcove.dev/docs/sending-logs/node).
