-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (45 loc) · 1.25 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
'use strict';
let request = require('request');
function colorByLevel(level) {
switch (level) {
case 'ERROR':
return 'ff0000';
case 'WARN':
return 'fffa00';
default:
return '00e5ff';
}
}
function appender (config, layout) {
let appender = (loggingEvent) => {
let level = loggingEvent.level.toString();
let color = colorByLevel(level);
request.post(
config.webhook,
{
json: {
title: level,
text: layout(loggingEvent),
themeColor : color
}
},
function (error, response, body) {
if (error || response.statusCode !== 200) {
config.errorHandler(body);
}
}
)
}
appender.shutdown = (done) => {
process.stdout.write('', done);
};
return appender;
}
function configure(config, layouts) {
let layout = layouts.messagePassThroughLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return appender(config, layout);
}
exports.configure = configure;