All files / core/semantic-log/src level.ts

100% Statements 40/40
87.5% Branches 7/8
100% Functions 4/4
100% Lines 40/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 31934x 31934x 1x 72x 72x 30397x 30397x 72x 1x 1x 15435x 15435x  
/**
 * Log levels (PRD R17 parity rows "log levels" and "level threshold filtering").
 *
 * The numeric values are the monorepo-wide convention and must not drift.
 */
 
export type LevelName = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
 
export const LEVELS: Readonly<Record<LevelName, number>> = {
    trace: 10,
    debug: 20,
    info: 30,
    warn: 40,
    error: 50,
    fatal: 60,
};
 
export const LEVEL_NAMES: Readonly<Record<number, LevelName>> = {
    10: 'trace',
    20: 'debug',
    30: 'info',
    40: 'warn',
    50: 'error',
    60: 'fatal',
};
 
/** Resolve a level name or number to its numeric value. */
export function levelValue(level: LevelName | number): number {
    return typeof level === 'number' ? level : LEVELS[level];
}
 
/** Resolve a numeric value to a name, falling back to the raw value. */
export function levelName(value: number): LevelName | string {
    return LEVEL_NAMES[value] ?? String(value);
}
 
/** True when `level` is at or above `threshold` (both inclusive). */
export function enabled(level: LevelName | number, threshold: LevelName | number): boolean {
    return levelValue(level) >= levelValue(threshold);
}