Represents a logger that can be used to log messages with different severity levels.

Change the static level property to change the severity level of messages that are logged.

Change the static transports property to change the way messages are logged.

Use Logger.ignore to ignore a severity level.

Example

const logger = new Logger("MyLogger");
Logger.level = LogLevel.DEBUG;
Logger.transports = { debug: print, info: print, warn: print, error: print };

Hierarchy

  • Logger

Constructors

Properties

name: string
level: LogLevel = LogLevel.INFO
transports: LoggerTransports = ...

Methods

  • Logs a debug message.

    Debug messages are less verbose than trace messages and should be used for debugging.

    Parameters

    • message: string

      The message to be logged.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.debug("This is a debug message");
  • Logs an error message.

    Error messages are the least verbose and should be used for logging errors.

    Parameters

    • message: string

      The message to be logged.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.error("This is an error message");
  • Logs an info message.

    Info messages are less verbose than debug messages and should be used for logging information.

    Parameters

    • message: string

      The message to be logged.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.info("This is an info message");
  • Logs a trace message.

    Trace messages are the most verbose and should only be used for debugging.

    Parameters

    • message: string

      The message to be logged.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.trace("This is a trace message");
  • Logs a warning message.

    Warning messages are less verbose than info messages and should be used for logging warnings.

    Parameters

    • message: string

      The message to be logged.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.warn("This is a warning message");
  • A transport function that does nothing.

    Use this to ignore a severity level as an alternative to setting the LogLevel, this can be useful where for example the trace transport is enabled but sending to an alternative location, but you want to disable info.

    Returns void

    Example

    const logger = new Logger("MyLogger");
    logger.transports = { debug: Logger.ignore, info: Logger.ignore, warn: print, error: print };

Generated using TypeDoc