Skip to content

ScifeonConsoleLogger

This class is used for logging to the console from pages, data loaders, etc.

import { inject, ConsoleLogger } from 'scifeon';
@inject(ConsoleLogger)
export class CustomPage {
constructor(logger) {
logger.debug('The logger can now be used.');
logger.setLevel(logger.logLevel.info);
logger.debug('This message will not be shown, as the log level hides it.');
}
}

Typically you would want to set the logger on the object (this) using this.logger = logger.

constructor(app: any, loggerName: string): ScifeonConsoleLogger

Section titled “constructor(app: any, loggerName: string): ScifeonConsoleLogger”

app is the contributions.json parsed as a Javascript-object. The loggerName should be something meaningful, e.g. ‘page.customPageId’. When the ScifeonConsoleLogger is injected using dependency injection, these values are automatically set.

This is a constant with the values defined in LogLevel.

setLevel(logLevel: [LogLevel](loglevel)): void

Section titled “setLevel(logLevel: [LogLevel](loglevel)): void”

Sets the level of logging for this logger instance.

Parameters

  • logLevel Matches a value of logLevel specifying the level of logging.

debug(message: string, ...rest: any[]): void

Section titled “debug(message: string, ...rest: any[]): void”

Logs a debug message.

Parameters

  • message: string The message to log.
  • ...rest: any[] The data to log.

Example

import { inject, ConsoleLogger } from 'scifeon';
@inject(ConsoleLogger)
export class CustomPage {
constructor(logger) {
logger.setLevel(logger.logLevel.debug);
logger.debug('The logger can now be used.');
const obj = { extraInfo: 'info' };
logger.debug('The rest parameter can be used to log extra information about', obj, ' and the logger itself', logger);
logger.debug('In the console you will we an array with these extra entries.');
}
}

info(message: string, ...rest: any[]): void

Section titled “info(message: string, ...rest: any[]): void”

Logs info.

Parameters

  • message: string The message to log.
  • ...rest: any[] The data to log.

warn(message: string, ...rest: any[]): void

Section titled “warn(message: string, ...rest: any[]): void”

Logs a warning.

Parameters

  • message: string The message to log.
  • ...rest: any[] The data to log.

error(message: string, ...rest: any[]): void

Section titled “error(message: string, ...rest: any[]): void”

Logs an error.

Parameters

  • message: string The message to log.
  • ...rest: any[] The data to log.