> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Errors and logging

The error handler that reports uncaught errors to Lynx, and a logger that sends device logs to a file on your computer. `import { LynxErrorHandler, LynxLogger } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/cart.ts"
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxLogger } from '@blotch/angular-lynx';

@Component({
  selector: 'app-cart',
  imports: [LYNX_ELEMENTS],
  template: `<view (bindtap)="checkout()"><text>Checkout</text></view>`,
})
export class Cart {
  readonly #logger = inject(LynxLogger);

  checkout(): void {
    this.#logger.info('Checkout tapped', { items: 3 });
  }
}
```

While `ng serve` runs, the message goes to `.dev-logs` in the folder you ran it from. Follow it with `tail -f .dev-logs`. See [Stream logs to your computer](/guide/debugging.md#stream-logs-to-your-computer).

## API

### `LynxErrorHandler`

```typescript
@Injectable()
class LynxErrorHandler implements ErrorHandler {}
```

Angular's `ErrorHandler` for Lynx. `provideRenderer()` provides it, so you don't add it yourself.

To add your own handling, extend it and provide your class after `provideRenderer()`:

```typescript title="src/app/app.config.ts"
import { type ApplicationConfig, ErrorHandler, Service } from '@angular/core';
import { LynxErrorHandler, provideRenderer } from '@blotch/angular-lynx';

@Service({ autoProvided: false })
class AppErrorHandler extends LynxErrorHandler {
  override handleError(error: unknown): void {
    // Send the error to your own service here.
    super.handleError(error);
  }
}

export const appConfig: ApplicationConfig = {
  providers: [
    provideRenderer(),
    { provide: ErrorHandler, useClass: AppErrorHandler },
  ],
};
```

### `LynxErrorHandler.handleError()`

```typescript
handleError(error: unknown): void;
```

Reports an uncaught error to Lynx as a fatal error, which can show Lynx's red error overlay on a device. A value that isn't an `Error` is wrapped in one. Unlike Angular's default handler, it doesn't call `console.error`.

### `LynxErrorHandler.onViewError()`

```typescript
onViewError(error: Error, details: ErrorDetails): void;
```

Angular calls this for a rendering error that an `@boundary` block caught. It reports the error to Lynx as a warning, not a crash, because the boundary already shows its `@error` content.

### `LynxLogger`

```typescript
@Injectable({ providedIn: 'root' })
class LynxLogger {}
```

Sends log messages from the device to the dev server, which writes them to `.dev-logs`. There's no browser console on a phone, so this is how you see logs from Lynx Explorer.

- **Development builds only.** In a production build, every method does nothing.
- **Sent through the background thread.** Your app runs on the [main thread](/guide/concepts/threads.md), which has no network access of its own. So each message goes to the background thread, which posts it to the dev server the app loaded from.
- **Objects and errors.** Objects and arrays print as indented JSON, and an `Error` prints with its stack. Other values, and an object JSON can't hold (such as a circular one), print as `String()` makes them.

### `LynxLogger.log()`, `info()`, `warn()`, `error()` and `debug()`

```typescript
log(...args: unknown[]): void;
info(...args: unknown[]): void;
warn(...args: unknown[]): void;
error(...args: unknown[]): void;
debug(...args: unknown[]): void;
```

Send one log entry at that level. The arguments print separated by spaces.

## Types

None of its own. `ErrorHandler` and `ErrorDetails` come from `@angular/core`.

## Related

- [Handling errors](/guide/error-handling.md): `@boundary` and error states.
- [Debugging](/guide/debugging.md): Lynx DevTool, logs and on-screen errors.
- [Bootstrap](/api/angular-lynx/bootstrap.md): what `provideRenderer()` provides.
