-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
39 lines (34 loc) · 1.09 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
'use strict';
const winston = require('winston');
const TransportStream = require('winston-transport');
const { LEVEL, MESSAGE } = require('triple-beam');
/**
* Transport for reporting errors to newrelic.
* @type {Newrelic}
* @extends {TransportStream}
*/
module.exports = class Newrelic extends TransportStream {
/**
* Constructor function for the Console transport object responsible for
* persisting log messages and metadata to a terminal or TTY.
* @param {!Object} [options={}] - Options for this instance.
*/
constructor(options = {}) {
const env = options.env || process.env.NODE_ENV;
super(options);
this.newrelic = require('./newrelicHelper')(env);
this.name = 'newrelic-winston';
}
/**
*
* @param {Object} info
* @param {function} callback
*/
log(info, callback) {
setImmediate(() => this.emit('logged', info));
if (info[LEVEL] === 'error') {
this.newrelic.noticeError(info[MESSAGE], typeof info.message === 'object' && info.message);
}
callback();
}
};