打字稿为温斯顿日志记录级别添加颜色
typescript add color to winston logging levels
我正在尝试为 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);
您不需要重新定义级别和颜色,只需将 colorize: true
传递给您的控制台传输即可:
new Logger({
transports: [
new transports.Console({
colorize: true
})
]
});
// 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.');
我正在尝试为 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);
您不需要重新定义级别和颜色,只需将 colorize: true
传递给您的控制台传输即可:
new Logger({
transports: [
new transports.Console({
colorize: true
})
]
});
// 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.');