Skip to main content

Logger.isLogLevel() method

Check if a value is the name of a valid log level.

Signature​

static isLogLevel(value: unknown): value is LogLevel;

Parameters​

Parameter

Type

Description

value

unknown

The value to check.

Returns​

value is LogLevel

True if the value is a valid log level name.

Remarks​

It is a type guard, to be used when the level comes from a source that is not checked by the compiler, like a command line option or an environment variable. It returns false for any value that is not one of the strings in levelNames, including non-string values, strings with different case, and the names of inherited properties (like 'toString').

  • added in v7.0.0

Example​

const name = process.env.LOG_LEVEL
if (Logger.isLogLevel(name)) {
log.level = name
} else {
log.error(`Level must be one of: ${Logger.levelNames.join(', ')}`)
}

Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.60.1.