-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (71 loc) · 2.11 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var util = require('util'),
winston = require('winston'),
raven = require('raven'),
Transport = require('winston/lib/winston/transports/transport.js').Transport;
var SENTRY_LOG_LEVELS = [
'debug',
'info',
'warning',
'error',
'fatal'
];
//
// ### function Sentry (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Sentry transport object responsible
// for persisting log messages and metadata to a terminal or TTY.
//
var Sentry = exports.Sentry = function (options) {
Transport.call(this, options);
options = options || {};
this.name = 'sentry';
this.dsn = options.dsn;
var clients = {};
SENTRY_LOG_LEVELS.forEach(function (level) {
clients[level] = new raven.Client(options.dsn, { level: level });
});
this._clients = clients;
};
util.inherits(Sentry, winston.Transport);
//
// Expose the name of this Transport on the prototype
//
Sentry.prototype.name = 'sentry';
//
// ### function _request (options, callback)
// #### @callback {function} Continuation to respond to when complete.
// Make a request to a winstond server or any Sentry server which can
// handle json-rpc.
//
//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
Sentry.prototype.log = function (level, msg, meta, tags, callback) {
var self = this, client;
if (typeof meta === 'function') {
callback = meta;
meta = {};
tags = {};
} else if (typeof tags === 'function') {
callback = tags;
tags = {};
}
if (this._clients.hasOwnProperty(level)) {
client = this._clients[level];
} else {
client = this._clients.debug;
}
client.captureMessage(msg, { extra: meta, tags: tags });
client.on('logged', function () {
self.emit('logged');
if (callback) callback(null, true);
});
client.on('error', function (err) {
return callback(err);
});
};