Logging
Aurelia provides a powerful logging API that allows you to display debug and error messages in your applications in a controlled manner.
Last updated
Was this helpful?
Was this helpful?
import { ILogger, resolve } from 'aurelia';
export class MyComponent {
private readonly logger: ILogger = resolve(ILogger).scopeTo('MyComponent');
public add() {
this.logger.debug(`Adding something`);
}
}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' }
]);
}
}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');
log.debug(`Debug message`);
log.warn(`This is a warning`);