3
我有如下配置:Winston/Node.js如何爲特定環境添加傳輸?
var winston = require('winston');
var Mail = require('winston-mail').Mail;
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ level: 'info', colorize: true }),
new (winston.transports.File)({ level: 'info', filename: './logs/logs.log',
new (Mail)({
to: '[email protected]',
from: '[email protected]',
subject: 'Errors occurred',
level: 'error',
host: 'smtp.xxxxx.xx',
username: '[email protected]',
password: 'xxxxx',
port: xxx
})
],
exceptionHandlers: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename: './logs/exceptions.log' }),
new (Mail)({
to: '[email protected]',
from: '[email protected]',
subject: 'Errors occurred',
level: 'error',
host: 'smtp.xxxxx.xx',
username: '[email protected]',
password: 'xxxxx',
port: xxx
})
]
});
我想補充的郵件傳輸只對生產環境不分期或開發。
我設置了不同的日誌級別如下:
if (process.env.NODE_ENV === 'development') {
logger.transports.console.level = 'debug';
logger.transports.file.level = 'debug';
}
有一個辦法做到這一點也與運輸?