> ## Documentation Index
> Fetch the complete documentation index at: https://docs.westyx.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Angular SDK - Custom logging

> Routing Angular SDK output to your own logging infrastructure, with structured fields.

Supply a logger and the SDK routes its output to it. Without one, output is
discarded.

## The interface

```ts theme={null}
interface NexusLogger {
  debug(message: string, fields?: Record<string, unknown>): void;
  info(message: string, fields?: Record<string, unknown>): void;
  warn(message: string, fields?: Record<string, unknown>): void;
  error(message: string, fields?: Record<string, unknown>): void;
}
```

You may implement any subset; missing levels are filled in with no-ops.

**Values travel in `fields`, never interpolated into `message`.** A message that
embeds its values produces a unique string per occurrence, which cannot be
grouped, counted or alerted on. A stable message plus structured fields can. An
error is carried as `fields.cause`.

## A console logger

```ts theme={null}
const consoleLogger: NexusLogger = {
  debug: (message, fields) => console.debug('[nexus]', message, fields),
  info:  (message, fields) => console.info('[nexus]', message, fields),
  warn:  (message, fields) => console.warn('[nexus]', message, fields),
  error: (message, fields) => console.error('[nexus]', message, fields),
};
```

```ts theme={null}
provideNexus({
  baseUrl: 'https://blue-ocean-a5rx7.westyx.dev',
  apiKey: 'wxp_...',
  logger: consoleLogger,
})
```

## What the SDK logs

| Level   | When                                                                                                                                                         |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `debug` | A sync applied or not modified, a stream event received, an out-of-order response discarded, the client closed, live updates unavailable in this environment |
| `info`  | The client is ready; the SDK has fallen back to polling                                                                                                      |
| `warn`  | A sync is being retried, payment is required, a quarantine, the stream was refused or ended                                                                  |
| `error` | The initial sync failed, a sync failed for a reason the SDK does not retry, a consumer callback threw                                                        |

Records carry fields such as `status`, `attempt`, `retry_in_ms`, `configs`,
`flags`, `key_type`, `event`, `consecutive_failures` and `cause`.

## Secrets never reach the logger

No log record contains a secret's value or a secret's key name, at any level, and
no record contains the API key. A test in the SDK drives a sync carrying a secret
through a capturing logger at the most verbose level and fails if either appears
anywhere in the output.

A configuration rejection naming the API key carries only its prefix - `wxp_...`

* never the material.

## A logger that throws cannot break the SDK

Every call is guarded. A logger is diagnostic equipment; a broken one does not
take the sync loop down with it.
