Friday, August 21, 2015

Logging in Aurelia

Just some quick notes on setting up logging in Aurelia

Add customer log appender

Create a file in ./resources/custom-log-appender.js and add the following class (or any other file as long as you change the import in the main.js file).

export class CustomLogAppender {
constructor(){} debug(logger, message,{ console.debug(`DEBUG [${}] ${message}`,; } info(logger, message,{`INFO [${}] ${message}`,; } warn(logger, message,{ console.warn(`WARN [${}] ${message}`,; } error(logger, message,{ console.error(`ERROR [${}] ${message}`,; } }

Update your main.js

import {LogManager} from 'aurelia-framework';
import {CustomLogAppender} from './resources/custom-log-appender';

LogManager.addAppender(new CustomLogAppender());

export function configure(aurelia) {
    // .developmentLogging()

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

and in your View Model

# ViewModel
import {LogManager} from 'aurelia-framework';
let logger = LogManager.getLogger('viewmodulename');

export class MyViewModel() {“Hah”);


  1. Thanks William. I was getting two log messages in my console and your code showing the .developmentLogging() call being commented out fixed it.

    Little posts like this are often just as good as the long ones.

    Thanks again.

  2. additional methods added to CustomLogAppender are not available in the VM through logger.additinalMethod(). Why is this? Id like to extend the logger to have additional methods that log to the backend.