如何使用log4js库(javascript)自定义记录器的颜色?
const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = 'debug';
logger.debug(`print this in red.`);
logger.debug(`print this in purple.`);
发布于 2021-05-17 16:54:12
只要使用术语转义序列即可。
const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = 'debug';
logger.debug(`print this in \u001b[31mred.`);
logger.debug(`print this in \u001b[35mpurple.`);
根据
man terminal-colors.d
它们如下所示:
0 to restore default color
1 for brighter colors
4 for underlined text
5 for flashing text
30 for black foreground
31 for red foreground
32 for green foreground
33 for yellow (or brown) foreground
34 for blue foreground
35 for purple foreground
36 for cyan foreground
37 for white (or gray) foreground
40 for black background
41 for red background
42 for green background
43 for yellow (or brown) background
44 for blue background
45 for purple background
46 for cyan background
47 for white (or gray) background
不同的代码必须用分号;
分隔,例如
logger.debug(`print this in \u001b[4;31mred\u001b[0m.`);
将打印下划线和红色的red
。
https://stackoverflow.com/questions/67573910
复制