Skip to content

Logging

From time to time, it is permissible to provide user feedback via the runtimes Console API. The primary usecase is to provide detailed error tracking in production or staging environments, and technical feedback in development environments.

To ensure the relevant information is displayed, the LogManager provides three methods of outputting to the console:

  1. All environments
  2. Development environment only
  3. Non-development environments

Configuration

The LogManager uses the mode configuration value which defaults to production. If you are in a development environment set mode to local.

Usage

LogManager, Logger and NullLogger all implement the LoggerInterface which requires implementations of 5 of the Console API's functions:
  • log
  • error
  • debug
  • info
  • warn

These all have the same method signature as the Console API.

/**
* Logger
*/
interface Logger {
log(message?: any, ...optionalParams: any[]): void;
info(message?: any, ...optionalParams: any[]): void;
debug(message?: any, ...optionalParams: any[]): void;
error(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
};

To output to the console only in a development environment use the DevelopmentLogger.

this.logger.dev.log(
'These are not the droids you are looking for',
droids
);

To output to the console only in a non-development environments use the ProductionLogger.

this.logger.production.log(
'These are not the droids you are looking for',
droids
);

Finally, to output to the console in all environments use the LogManager.

this.logger.log(
'These are not the droids you are looking for',
droids
);

Registration

The LogManager is registered as logger against the application Container. It is also exposed statically as Log.

Xedi.Log.dev.log(
'These are not the droids you are looking for',
droids
);
Edit this page on GitHub
1 contributorSmudge3806
Last edited by Smudge3806 on June 12, 2020