The Logger class provides a way to log messages with different levels of severity. It also allows for customization of the logging behavior through plugins.

Constructors

Properties

styles: Colors = picocolors

The color styles to use for formatting log messages.

Methods

  • Logs the given message content to the console at the debug log level. If config.debug is false, this method does nothing.

    Parameters

    • ...args: any[]

    Returns this

    This logger instance.

  • Logs an error message with the specified arguments.

    Parameters

    • ...args: any[]

    Returns this

    The logger instance.

  • Returns the singleton instance of the Logger class. If no instance has been created yet, it will create a new one with the given configuration. If an instance already exists, it will return the existing instance and set the given configuration.

    Parameters

    • config: LoggerConfig = {}

      The configuration options for the logger.

    Returns Logger

  • Logs an info message with the specified arguments.

    Parameters

    • ...args: any[]

    Returns this

    The logger instance.

  • Logs a normal message with the specified arguments.

    Parameters

    • ...args: any[]

    Returns this

    The logger instance.

  • Registers one or multiple plugins with the logger. Plugins can be added after the logger is instantiated. If a plugin has an initialize method, it will be executed immediately after registration.

    Parameters

    • plugin: BasePlugin | BasePlugin[]

      A single plugin or an array of plugins to register with the logger.

    Returns void

  • Logs a success message with the specified arguments.

    Parameters

    • ...args: any[]

    Returns this

    The logger instance.

  • Throws an error with the specified message and error name. If errName is not provided, the default error name is used. If message is a string, a new error is created with the given message. If message is an error, the error is cloned and the error name is set. If message is any other type, the error message is set to the stringified value of message.

    Parameters

    • message: unknown

      the error message or error object to throw

    • OptionalerrName: string

      the name of the error, defaults to DEFAULT_ERROR_NAME

    Returns void

  • Unregisters a plugin from the logger by its name. If the plugin has a destroy method, it will be called before the plugin is removed.

    Parameters

    • pluginName: string | string[]

      The name of the plugin to unregister. Can be a string or an array of strings.

    Returns void

  • Logs a warning message with the specified arguments.

    Parameters

    • ...args: any[]

    Returns this

    The logger instance.