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

# Debugging

A phone has no browser console to open. This page shows where your logs go, how to stream them to your computer, and how to inspect a running app.

## Where `console.log` goes

`console.log()`, `console.warn()` and the rest work on Lynx. Where you read the output depends on where the app runs:

| Your app runs in                                            | Read `console.*` output in                                                  |
| ----------------------------------------------------------- | --------------------------------------------------------------------------- |
| The [web preview](/guide/glossary.md#web-preview)           | Your browser's DevTools console, as for any web page                        |
| [Lynx Explorer](/guide/glossary.md#lynx-explorer)           | The **Console** panel of [Lynx DevTool](#inspect-the-app-with-lynx-devtool) |
| The apps `--platform` builds, with `ng build` or `ng serve` | Nowhere you can easily read. These apps don't include Lynx DevTool          |

On a device, `console.*` goes to Lynx's native logging, not to a panel on screen. On Android, `adb logcat` shows it under the tag `lynx`. To read logs without Lynx DevTool, use `LynxLogger`.

- **Lynx's `console` has fewer methods.** `log`, `info`, `warn`, `error`, `debug`, `time`, `timeEnd`, `group`, `groupEnd`, `table` and `count` work. There's no `trace`, `assert` or `dir`, so calling one throws.
- **`console.error()` also reports an error.** Lynx passes each call to the app as an error, as it does an uncaught one.

## Stream logs to your computer

`LynxLogger` sends log lines from the device to a file on your computer while `ng serve` runs.

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

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="add()">
      <text>Count: {{ count() }}</text>
    </view>
  `,
})
export class App {
  readonly count = signal(0);
  readonly #logger = inject(LynxLogger);

  add(): void {
    this.count.update((n) => n + 1);
    this.#logger.log('Tapped, count is', this.count());
  }
}
```

In a second terminal, in the folder where you ran `ng serve`, follow the log file:

```bash
tail -f .dev-logs
```

Each call becomes one line with the time and the level:

```bash
10:42:07.311 LOG Tapped, count is 1
```

- **How it reaches you.** The app sends each line to the dev server it loaded from, over your network, so it arrives wherever the app can load. It works from any code, including event handlers.
- **The file.** Lines go to `.dev-logs` in the folder you ran `ng serve` from. `ng serve` prints its full path when it starts, and each run starts the file fresh. `ng add` adds `.dev-logs` to your `.gitignore`.
- **The methods.** `log()`, `info()`, `warn()`, `error()` and `debug()`. The level shows in each line.
- **Objects and errors.** Objects and arrays print as indented JSON, and an `Error` prints with its stack. Other values print as `String()` makes them.
- **Development only.** `LynxLogger` does nothing in production builds, so you can leave the calls in. A shipped app sends nothing.

:::tip Nothing in `.dev-logs`?
Check that `ng serve` builds a development build. `ng serve -c production`, or a build target without a `development` configuration, serves a production build, where `LynxLogger` does nothing.
:::

## Inspect the app with Lynx DevTool

[**Lynx DevTool**](/guide/glossary.md#lynx-devtool) is a desktop app from the Lynx team: browser DevTools for an app running on a phone. Its panels are:

- **Elements:** inspect and change the elements on screen.
- **Console:** read logs and run JavaScript.
- **Sources:** debug your JavaScript.
- **Layers:** look at the app's layers in 3D to find rendering problems.
- **Trace,** in the top bar: record a performance trace. See [Profiling performance](/guide/profiling.md).

To connect it:

1. Download Lynx DevTool from its [GitHub releases page](https://github.com/lynx-family/lynx-devtool/releases).
2. In Lynx Explorer, open the **Switch** page and turn on **Lynx Debug** and **Lynx DevTool**. The same switch lets the dev server reload your app when you save a change it can't apply in place.
3. Connect the phone to your computer with a USB cable. Lynx DevTool finds it.

Lynx's [DevTool guide](https://lynxjs.org/guide/devtool) covers each panel in depth.

## Show errors on screen

When nothing is connected, put the latest error on screen. This helps most in the apps `--platform` builds, with `ng build` or `ng serve`, which show no error screen of their own.

Extend [`LynxErrorHandler`](/guide/error-handling.md) so it copies each error into a signal:

```typescript title="src/app/error-log.ts"
import { type ErrorDetails, inject, Service, signal } from '@angular/core';
import { LynxErrorHandler } from '@blotch/angular-lynx';

/** Holds the latest error as text, for the screen. */
@Service()
export class ErrorLog {
  readonly last = signal('');
}

@Service({ autoProvided: false })
export class ShowErrorsHandler extends LynxErrorHandler {
  readonly #log = inject(ErrorLog);

  override handleError(error: unknown): void {
    super.handleError(error);
    this.#show(error);
  }

  override onViewError(error: Error, details: ErrorDetails): void {
    super.onViewError(error, details);
    this.#show(error);
  }

  #show(error: unknown): void {
    // Angular can call the handler in the middle of rendering, where writing
    // a signal throws NG0600. Wait until rendering has finished.
    queueMicrotask(() => this.#log.last.set(String(error)));
  }
}
```

Register it after `provideRenderer()`, which registers the default handler:

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

export const appConfig: ApplicationConfig = {
  providers: [
    provideRenderer(),
    { provide: ErrorHandler, useClass: ShowErrorsHandler }, // [!code highlight]
  ],
};
```

Then show it in your root component:

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

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS],
  template: `
    <view>
      <!-- Your app -->

      @if (errors.last()) {
        <view style="background-color: #b91c1c; padding: 8px;">
          <text style="color: white; font-size: 12px; word-break: break-all;">
            {{ errors.last() }}
          </text>
        </view>
      }
    </view>
  `,
})
export class App {
  readonly errors = inject(ErrorLog);
}
```

- **Why a signal.** Under zoneless change detection, Angular re-renders only when a signal changes. A template that reads a plain variable never updates.
- **Errors outside Angular.** An unhandled promise rejection, for example, skips the error handler. AngularLynx still saves it, as text in `globalThis.__lynxLastError`. That's a plain string, so read it on demand, e.g. from a tap handler that copies it into `errors.last`.
- **Before you ship,** remove the display. It's a development aid, not something to show users.

## Related

- [Handling errors](/guide/error-handling.md): what happens when code throws, and `@boundary`.
- [Profiling performance](/guide/profiling.md)
- [`LynxLogger` and `LynxErrorHandler` API](/api/angular-lynx/errors-and-logging.md)
- [Lynx DevTool guide](https://lynxjs.org/guide/devtool) on lynxjs.org
