@nestjs/common
Version:
Decorators, pipes, exceptions and utilities for NestJS applications: @Controller(), @Injectable(), @Body(), ValidationPipe, HttpException and more.
21 lines (20 loc) • 853 B
JavaScript
import { LOG_LEVELS } from '../log-levels.constant.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;
}