Skip to content

Commit a7ed9cc

Browse files
alexk-blackopsalexk-blackops
authored andcommitted
minor fixes
1 parent 504c86b commit a7ed9cc

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

lib/api.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
var os = require('os'),
22
url = require('url'),
33
util = require('util'),
4+
45
send = require('./sender'),
56
logger = require('./logger'),
67
CONFIG = require('../config/config'),
8+
79
pkginfo = require('pkginfo')(module, 'name'),
810

911
appname = module.exports.name, //name of the app from package.json
@@ -67,10 +69,10 @@ module.exports.methods = {
6769
throw new TypeError('Settings are not provided');
6870
}
6971

70-
if (setting.apiKey && typeof (settings.apiKey) === 'string') {
72+
if (settings.apiKey && typeof (settings.apiKey) === 'string') {
7173
opt.headers['X-Stackify-Key'] = settings.apiKey;
7274
CONFIG.APPNAME = appname;
73-
CONFIG.ENV = settings.env;
75+
CONFIG.ENV = settings.env || null;
7476
send(opt, callback, fail);
7577
} else {
7678
throw new TypeError('You have to pass API key');

lib/exception.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ var qs = require('querystring'),
1717
},
1818
fail_counter = 0,
1919

20+
cb = function () {
21+
console.log('sent', util.inspect(logger.storage, {depth: null}));
22+
}
23+
2024
//retry the request if it failed
2125
fail = function () {
2226
fail_counter += 1;
@@ -34,10 +38,10 @@ var qs = require('querystring'),
3438
} else {
3539
console.log('not identified yet');
3640
}
37-
},
41+
};
3842

39-
// flag used for not catching the same exception twice (inside and outside of the createServer method)
40-
excCaught = false;
43+
// flag used for not catching the same exception twice (inside and outside of the createServer method)
44+
module.exports.excCaught = excCaught = false;
4145

4246
module.exports = {
4347
// Pure Node apps exception catching

lib/logger.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
var api = require('./api'),
2-
util = require('util'),
3-
CONFIG = require('../config/config'),
1+
var util = require('util'),
2+
api = require('./api'),
3+
CONFIG = require('../config/config'),
44
helpers = require('./helpers'),
5-
error = require('./error'),
5+
error = require('./error'),
6+
exc = require('./exception'),
67

78
storage = [],
89

@@ -26,7 +27,7 @@ var api = require('./api'),
2627
// handler for sending logs
2728
sendLogs = function (length) {
2829
var self = this,
29-
data = storage.slice(0, length),
30+
data = storage.slice(0, length || CONFIG.MSG_LIMIT),
3031

3132
/* if request is succesful remove messages from the queue, change the timeout for the next checkLogs call,
3233
switch the flag, send another batch (if there are enough messages in the queue)
@@ -133,7 +134,7 @@ module.exports.methods = {
133134

134135
if ((level.toLowerCase() === 'error' && checkErrorLimitMessage(rec.Ex)) || level.toLowerCase() !== 'error') {
135136
storage.push(rec);
136-
console.log('logged');
137+
console.log('logged', storage.length);
137138

138139
// remove the earliest message from the queue if message cap is exceeded
139140
if (storage.length === CONFIG.MSG_CAP) {
@@ -155,7 +156,7 @@ module.exports.methods = {
155156
timeout = setTimeout(checkLogs, CONFIG.SCAN_TIMER);
156157

157158
if (storage.length >= CONFIG.MSG_LIMIT) {
158-
sendLogs();
159+
sendLogs(exc.excCaught ? storage.length : null);
159160
}
160161
},
161162

lib/sender.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ module.exports = function sender(options, cb, fail) {
1515
if (!error) {
1616
if (response.statusCode === 200) {
1717
if (cb) {
18-
cb(body);
19-
console.log('success');
20-
}
18+
cb(body); }
2119
} else {
2220
if (fail) {
2321
fail();
24-
console.log('fail:', body);
2522
}
2623
}
2724
} else {

0 commit comments

Comments
 (0)