Go to repository

Class Logger

This class provides a centralize way to report messages in the terminal through the application, including messages that are always printed, debug information, error messages and others.

Constructors

Create a new logger

Parameters

Returns Logger

Properties

Private
_on: boolean

Whether this logger is turned on

level: LogLevel

Methods

Log a message as debug information, if the level allows it and the logger is on.

Parameters

  • msg: string

    The message to print.

  • Optional
    style: string

    A style on which to print the message

Returns this

the receiver logger.

Log a message as an error, if the level allows it and the logger is on.

Parameters

  • msg: string

    The message to print.

  • Optional
    style: string

    A style on which to print the message

Returns this

the receiver logger.

Log a message as information, if the level allows it and the logger is on.

Parameters

  • msg: string

    The message to print.

  • Optional
    style: string

    A style on which to print the message

Returns this

the receiver logger.

Private

Answers if the first level is greater or equal than the second one.

Parameters

  • level1: LogLevel

    The first level to compare

  • level2: LogLevel

    The second level to compare.

Returns boolean

true if the first level is greater or equal than the second, false otherwise.

Log a message regardless of the active level, but only if the logger is on.

Parameters

  • msg: string

    The message to print.

  • Optional
    style: string

    A style on which to print the message

Returns this

the receiver logger.

Turn this logger off. If already off, nothing happens.

Returns this

the receiver logger.

Turn this logger on. If already on, nothing happens.

Returns this

the receiver logger.

Private

Print the given message in the terminal, if the log level allows it and the logger is on.

Parameters

  • msg: string

    The message to print

  • Optional
    style: string

    The style to use for printing.

  • Optional
    actualLevel: LogLevel

    The actual level on which the message should be printed.

Returns void

Log a message as an warning, if the level allows it and the logger is on.

Parameters

  • msg: string

    The message to print.

  • Optional
    style: string

    A style on which to print the message

Returns this

the receiver logger.