Logging

Overview

Aurelia provides a flexible logging system that allows developers to implement structured and configurable logging across their applications. The logging mechanism is designed to be lightweight, extensible, and easy to use, supporting various log levels and custom output methods.

Getting Started

Importing Logging Utilities

To begin using logging in Aurelia, you'll need to import the necessary modules:

import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';

Basic Configuration

To set up logging, you'll typically configure it in your application's main configuration:

export function configure(aurelia) {
  // Add a console appender
  LogManager.addAppender(new ConsoleAppender());

  // Optionally set a default log level
  LogManager.setLevel(LogManager.logLevel.debug);

  aurelia.use
    .standardConfiguration()
    .globalResources();

  aurelia.start().then(() => aurelia.setRoot());
}

Creating a Logger

To create a logger in your application or component:

Log Levels

Aurelia supports multiple log levels to control the verbosity of logging:

Log Level
Description

none

No logging

error

Critical errors only

warn

Warnings and errors

info

Informational messages, warnings, and errors

debug

Detailed debugging information, including all previous levels

Setting Log Levels

You can set the global log level using:

Note: Log levels are hierarchical. Setting a level includes all levels above it.

Appenders

What are Appenders?

Appenders are responsible for outputting log messages. Aurelia provides a default ConsoleAppender, but you can create custom appenders.

Default ConsoleAppender

The ConsoleAppender writes log messages to the browser console:

Creating Custom Appenders

You can create a custom appender by implementing the Appender interface:

Advanced Usage

Multiple Appenders

You can add multiple appenders to route logs to different destinations:

Last updated

Was this helpful?