我试图为winston的日志记录级别添加颜色。输出仍然没有颜色。
import { addColors , Logger, LoggerInstance, transports, AbstractConfigSet } from "winston";
let level = "debug";
const levels = {
debug: 0,
info: 1,
warn: 2,
error: 3
};
const colors = {
debug: 'blue',
info: 'green',
warn: 'yellow',
error: 'red'
};
export const log: LoggerInstance = new Logger({
transports: [ new transports.Console() ],
level,
levels
});
addColors(colors);
答案 0 :(得分:4)
// for winston 3
var winston = require('winston');
const logger = module.exports = winston.createLogger({
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.simple()
)
});;;
logger.log('info', 'This is an information message.');
答案 1 :(得分:1)
您不需要重新定义关卡和颜色,只需将colorize: true
传递给您的控制台传输:
new Logger({
transports: [
new transports.Console({
colorize: true
})
]
});