npm install -S winston winston-slack-webhook
var winston = require('winston');
var SlackWebHook = require('winston-slack-webhook').SlackWebHook;
var logger = new winston.Logger({
level: 'info',
transports: [
new (winston.transports.Console)(),
new SlackWebHook({
level: 'error',
webhookUrl: 'https://hooks.slack.com/services/xxx/xxx/xxx',
channel: '#error_logs',
username: 'logger'
})
]
});
logger.info('Created logger');
logger.error('Something wrong!!');
var winston = require('winston');
var SlackWebHook = require('winston-slack-webhook').SlackWebHook;
var logger = new winston.Logger();
logger.add(SlackWebHook, {
level: 'error',
webhookUrl: 'https://hooks.slack.com/services/xxx/xxx/xxx',
channel: '#error_logs',
username: 'logger'
});
- webhookUrl: Slack incoming webhook url (required)
- channel: Slack channel to post to. (optional 1)
- username: User name to post as. (optional 1)
- iconEmoji: Icon to post as. (optional 1)
- iconUrl: Icon to post as. (either iconEmoji or iconUrl will be used)
- formatter: Custom function to format logs. (optional)
- level: Level to log. (global settings will be applied if level is blank)
- unfurlLinks: Whether to unfurl links in Slack (optional)