slack.js
1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
var Slack = require('slack-node');
var layouts = require('../layouts');
var layout;
var slack, config;
function slackAppender(_config, _layout) {
layout = _layout || layouts.basicLayout;
return function (loggingEvent) {
var data = {
channel_id: _config.channel_id,
text: layout(loggingEvent, _config.timezoneOffset),
icon_url: _config.icon_url,
username: _config.username
};
slack.api('chat.postMessage', {
channel: data.channel_id,
text: data.text,
icon_url: data.icon_url,username: data.username}, function (err, response) {
if (err) { throw err; }
});
};
}
function configure(_config) {
if (_config.layout) {
layout = layouts.layout(_config.layout.type, _config.layout);
}
slack = new Slack(_config.token);
return slackAppender(_config, layout);
}
exports.name = 'slack';
exports.appender = slackAppender;
exports.configure = configure;