Home Manual Reference Source
import LoggerSingleton from 'ievv_jsbase/lib/log/LoggerSingleton'
public class | source

LoggerSingleton

A logging system.

Example:

Create and use a logger
import LoggerSingleton from 'ievv_jsbase/lib/log/LoggerSingleton';
let mylogger = new LoggerSingleton().loggerSingleton.getLogger('myproject.MyClass');
mylogger.debug('Hello debug world');
mylogger.info('Hello info world');
mylogger.warning('Hello warning world');
mylogger.error('Hello error world');
Set a default loglevel for all loggers
import LOGLEVEL from 'ievv_jsbase/lib/log/loglevel';
new LoggerSingleton().setDefaultLogLevel(LOGLEVEL.DEBUG);
Set a custom loglevel for a single logger
import LOGLEVEL from 'ievv_jsbase/lib/log/loglevel';
new LoggerSingleton().getLogger('mylogger').setLogLevel(LOGLEVEL.DEBUG);

Constructor Summary

Public Constructor
public

Get an instance of the singleton.

Method Summary

Public Methods
public

Get a string that summarize information about all the loggers.

public

Get the default log level.

public

Get a logger.

public

Get the number of loggers registered using getLogger.

public

Get the names of all the registered loggers.

public

Get textual name for the default log level.

public

reset()

Reset to default log level, and clear all custom loggers.

public

setDefaultLogLevel(logLevel: *)

Set the default loglevel.

Public Constructors

public constructor source

Get an instance of the singleton.

The first time this is called, we create a new instance. For all subsequent calls, we return the instance that was created on the first call.

Public Methods

public getDebugInfoString(): string source

Get a string that summarize information about all the loggers. The string has a list of loglevels with their loglevel. Perfect for debugging.

Intended for debugging. The format of the string may change.

Return:

string

public getDefaultLogLevel(): int source

Get the default log level.

Defaults to LogLevels#WARNING if not overridden with {@LoggerSingleton#setDefaultLogLevel}.

Return:

int

One of the loglevels defined in LogLevels

public getLogger(name: string): Logger source

Get a logger.

Params:

NameTypeAttributeDescription
name string

A name for the logger. Should be a unique name, so typically the full import path of the class/function using the logger.

Return:

Logger

public getLoggerCount(): number source

Get the number of loggers registered using getLogger.

Return:

number

The number of loggers.

public getLoggerNameArray(): Array source

Get the names of all the registered loggers.

Return:

Array

Sorted array with the same of the loggers.

public getTextualNameForDefaultLogLevel(): string source

Get textual name for the default log level.

Intended for debugging. The format of the string may change.

Return:

string

public reset() source

Reset to default log level, and clear all custom loggers.

public setDefaultLogLevel(logLevel: *) source

Set the default loglevel.

All loggers use this by default unless you override their loglevel.

Params:

NameTypeAttributeDescription
logLevel *

The log level. Must be one of the loglevels defined in LogLevels.

Throw:

RangeError

if LogLevels#validateLogLevel fails.

Example:

Override loglevel of a specific logger
import LoggerSingleton from 'ievv_jsbase/log/LoggerSingleton';
import LOGLEVEL from 'ievv_jsbase/log/loglevel';
let loggerSingleton = new LoggerSingleton();
loggerSingleton.getLogger('mylogger').setLogLevel(LOGLEVEL.DEBUG);