-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
43 lines (35 loc) · 995 Bytes
/
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
'use strict';
const winston = require('winston');
module.exports = class WinstonSnsSumoLogic extends winston.Transport {
constructor(options) {
super(options);
this.name = 'sns sumo logic transport';
this.level = options.level || 'info';
if (!options.sns) {
throw new Error('options.sns is required');
}
this.sns = options.sns;
if (!options.topicArn) {
throw new Error('options.topicArn is required');
}
this.topicArn = options.topicArn;
this.body = options.body || {};
}
log(info, callback) {
setImmediate(() => {
this.emit('logged', info);
});
// this is the required sumo logic timestamp for json logs
const body = Object.assign({}, this.body, {
timestamp: Date.now(),
level: info.level,
message: info.message,
meta: info.meta
});
this.sns.publish({
TopicArn: this.topicArn,
Subject: 'Winston Log',
Message: JSON.stringify(body)
}, callback);
}
};