UNPKG

@nestjs/common

Version:

Nest - modern, fast, powerful node.js web framework (@common)

21 lines (20 loc) 848 B
import { LOG_LEVELS } from '../logger.service.js'; import { isLogLevel } from './is-log-level.util.js'; /** * @publicApi */ export function filterLogLevels(parseableString = '') { const sanitizedString = parseableString.replaceAll(' ', '').toLowerCase(); if (sanitizedString[0] === '>') { const orEqual = sanitizedString[1] === '='; const logLevelIndex = LOG_LEVELS.indexOf(sanitizedString.substring(orEqual ? 2 : 1)); if (logLevelIndex === -1) { throw new Error(`parse error (unknown log level): ${sanitizedString}`); } return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1); } else if (sanitizedString.includes(',')) { return sanitizedString.split(',').filter(isLogLevel); } return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS; }