This module provides a logging utility for different log levels in a game or application. It defines constants for various log levels such as Master, Slave, and Action. The `log` function allows logging messages at specified levels, filtering out messages that do not match the provided log level.
PropertiesName | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LOG_LEVELS | Object | An object containing constants for each log level.Properties
|
- Source
Example
// Example usage:
import { log, LOG_LEVELS } from './log';
log([LOG_LEVELS.MASTER, LOG_LEVELS.SLAVE], LOG_LEVELS.MASTER, "This is a master log message.");
log([LOG_LEVELS.SLAVE], LOG_LEVELS.SLAVE, "This is a slave log message.");
log([LOG_LEVELS.ACTION], LOG_LEVELS.ACTION, "This is an action log message.");
Methods
(static) log(levelArray, logLevel, …args) → {void}
This function checks if the provided log level exists in the levelArray. If it does, it logs the messages to the console with the specified log level prefix. The log messages are formatted with the log level in square brackets followed by the message. This is useful for filtering log messages based on their importance or category.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
levelArray | Array.<string> | An array of log levels to filter the messages. | |
logLevel | string | The log level to check against the levelArray. | |
args | any | <repeatable> | The messages to log. These can be any type of data that can be logged to the console. |
- Source
Returns:
- Type:
- void