0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00
verdaccio/packages/logger-prettify/src/levels.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

import { black, blue, cyan, green, magenta, red, white, yellow } from 'kleur';
2019-07-20 19:54:33 +02:00
export type LogLevel = 'trace' | 'debug' | 'info' | 'http' | 'warn' | 'error' | 'fatal';
export type LevelCode = number;
export function calculateLevel(levelCode: LevelCode): LogLevel {
switch (true) {
2021-04-02 15:59:47 +02:00
case levelCode === 10:
return 'trace';
2021-04-02 15:59:47 +02:00
case levelCode === 20:
return 'debug';
2021-04-02 15:59:47 +02:00
case levelCode === 25:
return 'http';
2021-04-02 15:59:47 +02:00
case levelCode === 30:
return 'info';
case levelCode === 40:
return 'warn';
2021-04-02 15:59:47 +02:00
case levelCode === 50:
return 'error';
2021-04-02 15:59:47 +02:00
case levelCode === 60:
return 'fatal';
default:
return 'fatal';
}
}
export const levelsColors = {
fatal: red,
error: red,
warn: yellow,
http: magenta,
info: cyan,
debug: green,
trace: white,
2019-07-20 19:54:33 +02:00
};
enum ARROWS {
LEFT = '<--',
RIGHT = '-->',
EQUAL = '-=-',
NEUTRAL = '---',
2019-07-20 19:54:33 +02:00
}
export const subSystemLevels = {
color: {
in: green(ARROWS.LEFT),
out: yellow(ARROWS.RIGHT),
fs: black(ARROWS.EQUAL),
default: blue(ARROWS.NEUTRAL),
},
white: {
in: ARROWS.LEFT,
out: ARROWS.RIGHT,
fs: ARROWS.EQUAL,
default: ARROWS.NEUTRAL,
},
};