> For the complete documentation index, see [llms.txt](https://docs.aurelia.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aurelia.io/getting-to-know-aurelia/services-and-runtime-hooks/logging.md).

# Logging

Aurelia provides a powerful logging API that allows you to display debug and error messages in your applications in a controlled manner.

## Getting started

Aurelia comes with a flexible and powerful logging system that allows you to display debug and error messages in your applications in a slightly better way than using native `console.log` statements.

Reasons to use logging inside of your apps and plugins include helpful debug messages for other developers (living comments) or displaying helpful information to the end-user in the console when something goes wrong.

The logger is injected using dependency injection into your components:

```typescript
import { ILogger, resolve } from 'aurelia';

export class MyComponent {
  private readonly logger: ILogger = resolve(ILogger).scopeTo('MyComponent');
}
```

In this example, we scope our logger to our component. But scoping is optional, and the logger can be used without using `scopeTo`however, we highly recommend using the scoping feature to group your messages in the console.

## Logging methods

Just like `console.log` the Aurelia logger supports the following methods:

* debug
* info
* warn
* trace

These methods are called on the logger instance you injected into your component.

```typescript
import { ILogger, resolve } from 'aurelia';

export class MyComponent {
  private readonly logger: ILogger = resolve(ILogger).scopeTo('MyComponent');

  public add() {
      this.logger.debug(`Adding something`);
  }
}
```

Just like `console.log` you can also pass in values such as strings, booleans, arrays and objects.

```typescript
import { ILogger, resolve } from 'aurelia';

export class MyComponent {
  private readonly logger: ILogger = resolve(ILogger).scopeTo('MyComponent');

  public add() {
      this.logger.debug(`Adding something`, [
          { prop: 'value', something: 'else' }
      ]);
  }
}
```

## Creating a logger

To create a custom logger for your applications and plugins, you can create a more reusable wrapper around the logging APIs to use in your applications.

```typescript
import { DI, ILogger, ConsoleSink, IPlatform, LogLevel, LoggerConfiguration, Registration } from '@aurelia/kernel';
import { BrowserPlatform } from '@aurelia/platform-browser';

const PLATFORM = BrowserPlatform.getOrCreate(globalThis);

const staticContainer = DI.createContainer();
staticContainer.register(Registration.instance(IPlatform, Registration));
staticContainer.register(LoggerConfiguration.create({ sinks: [ConsoleSink], level: LogLevel.fatal }));

export const log = staticContainer.get(ILogger).scopeTo('My App');

```

It might look like a lot of code, but this logger implementation will create a scoped logger wrapper you can import into your applications and use in the following way:

```typescript
log.debug(`Debug message`);
log.warn(`This is a warning`);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aurelia.io/getting-to-know-aurelia/services-and-runtime-hooks/logging.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
