/* istanbul ignore next */
/**
* Class with a logger interface. Messages are only logged to console if
* their log level is smaller or equal than the current log level.
*
* @author {@link https://github.com/Mugen87|Mugen87}
*/
class Logger {
/**
* Sets the log level for the logger. Allow values are: *LOG*,
* *WARN*, *ERROR*, *SILENT*. The default level is *WARN*. The constants
* are accessible over the *Logger.LEVEL* namespace.
*
* @param {Number} level - The log level.
*/
static setLevel( level ) {
currentLevel = level;
}
/**
* Logs a message with the level *LOG*.
*
* @param {...Any} args - The arguments to log.
*/
static log( ...args ) {
if ( currentLevel <= Logger.LEVEL.LOG ) console.log( ...args );
}
/**
* Logs a message with the level *WARN*.
*
* @param {...Any} args - The arguments to log.
*/
static warn( ...args ) {
if ( currentLevel <= Logger.LEVEL.WARN ) console.warn( ...args );
}
/**
* Logs a message with the level *ERROR*.
*
* @param {...Any} args - The arguments to log.
*/
static error( ...args ) {
if ( currentLevel <= Logger.LEVEL.ERROR ) console.error( ...args );
}
}
Logger.LEVEL = Object.freeze( {
LOG: 0,
WARN: 1,
ERROR: 2,
SILENT: 3
} );
let currentLevel = Logger.LEVEL.WARN;
export { Logger };