@plugjs/plug
Version:
PlugJS Build System ===================
50 lines • 1.63 kB
JavaScript
// Those are all our defined log levels: please note the absence of the ZERO
// as it's falsy and 0x1fffffffffffff is Number.MAX_SAFE_INTEGER as a constant
/** The `TRACE` log level */
export const TRACE = 10;
/** The `DEBUG` log level */
export const DEBUG = 20;
/** The `INFO` log level */
export const INFO = 30;
/** The `NOTICE` log level (our default) */
export const NOTICE = 40;
/** The `WARN` log level */
export const WARN = 50;
/** The `ERROR` log level */
export const ERROR = 60;
/** The `OFF` log level (no logs are emitted) */
export const OFF = 0x1fffffffffffff;
/** All our known log levels */
export const logLevels = Object.freeze({ TRACE, DEBUG, INFO, NOTICE, WARN, ERROR, OFF });
/**
* Convert a `string` (a {@link LogLevelString}) into a {@link LogLevel}.
*
* If the level specified is not a {@link LogLevelString}, the {@link NOTICE}
* level (our default) will be returned.
*/
export function getLevelNumber(level) {
const _level = level.toUpperCase();
return (_level in logLevels ? logLevels[_level] : NOTICE);
}
/**
* Convert a `number` (a {@link LogLevel}) into a {@link LogLevelName}.
*
* If the level specified is not precisely a {@link LogLevel}, the
* closer {@link LogLevelName} will be returned.
*/
export function getLevelName(level) {
if (level <= TRACE)
return 'trace';
if (level <= DEBUG)
return 'debug';
if (level <= INFO)
return 'info';
if (level <= NOTICE)
return 'notice';
if (level <= WARN)
return 'warn';
if (level <= ERROR)
return 'error';
return 'off';
}
//# sourceMappingURL=levels.js.map