Skip to content

Commit 52a9353

Browse files
alexk-blackopsalexk-blackops
authored andcommitted
some minor fixes
1 parent 155b497 commit 52a9353

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ stackify.start(options);
2626
The following options could be passed. 'apiKey' is the only one that required:
2727
* __apiKey:__ client license key
2828
* __env:__ environment name
29-
* __proxy:__ proxy server if you want to send requests via proxy
29+
* __proxy:__ proxy server if you want to send requests via proxy.
30+
31+
* Notice: * stackify-logger sends synchronous requests before any `process.exit()` calls in your code. Sending via proxy wouldn't be possible in this case.
32+
3033
* __exitOnError:__ boolean flag indicating whether to shutdown the server after logging an uncaught exception, defaults to false
3134

3235
#### Using with Winston
3336

3437
```bash
38+
$ npm install winston
3539
$ npm install winston-stackify
3640
```
3741

@@ -54,7 +58,8 @@ stackify.info(message [, meta1, ... , metaN])
5458
stackify.warn(message [, meta1, ... , metaN])
5559
stackify.error(message [, meta1, ... , metaN])
5660
```
57-
Message must be a string
61+
62+
Message must be a string.
5863
meta1 ... metaN - a list of additional parameters of any type.
5964
The timestamp will be added to every message by default.
6065

@@ -111,6 +116,9 @@ app.use(stackify.expressExceptionHandler);
111116

112117
To handle exceptions correctly put this right after all route handlers.
113118

119+
#### Troubleshooting
120+
When request to Stackify fails for some reason, an error message is being printed to your `process.stderr` stream
121+
114122
## License
115123

116124
Copyright 2014 Stackify, LLC.

config/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818

1919
},
2020
IDENTIFY_DELAY: 300000, // 5 minutes delay if identifyApp call failed
21-
COOKIE_MASK: 'X-MASKED-X' // cookie headers and values mask
21+
COOKIE_MASK: 'X-MASKED-X', // cookie headers and values mask
2222
LOGGER_VERSION: 'Node.js Stackify v.1.0',
23-
X-STACKIFY-PV: 'V1'
23+
X_STACKIFY_PV: 'V1'
2424
};

lib/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports.getURL = function getURL(req) {
122122
*/
123123

124124
module.exports.getAppName = function getAppName() {
125-
var pjsonPath = path.join(process.env.PWD, 'package.json'),
125+
var pjsonPath = path.join(process.cwd(), 'package.json'),
126126
pjson;
127127
try {
128128
pjson = require(pjsonPath);
@@ -185,6 +185,6 @@ module.exports.getHeaders = function getHeaders() {
185185
return {
186186
'Content-Type': 'application/json',
187187
'X-Stackify-Key': CONFIG.APIKEY,
188-
'X-Stackify-PV': CONFIG.X-STACKIFY-PV
188+
'X-Stackify-PV': CONFIG.X_STACKIFY_PV
189189
};
190190
};

lib/logger.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,25 @@ var api = require('./api'),
2828
/* if request is succesful remove messages from the queue,
2929
send another batch (if there are enough messages in the queue)
3030
*/
31-
success = function () {
32-
storage = storage.slice(chunk); // remove this chunk from the queue
33-
length -= chunk;
34-
api.lastApiError = 0; // reset the last HTTP error
35-
36-
if (length) {
37-
chunk = Math.min(length, CONFIG.MSG.MAX_BATCH_SIZE);
38-
data = storage.slice(0, chunk);
39-
api.methods.postLogs(data, success, shutdown);
40-
} else {
41-
// full batch is sent, set timeout for the next request
42-
if (cb) {
43-
// if exception is caught run next middleware or check if we need to shutdown the server
44-
cb();
31+
success = function (response) {
32+
if (response.success) {
33+
storage = storage.slice(chunk); // remove this chunk from the queue
34+
length -= chunk;
35+
api.lastApiError = 0; // reset the last HTTP error
36+
37+
if (length) {
38+
chunk = Math.min(length, CONFIG.MSG.MAX_BATCH_SIZE);
39+
data = storage.slice(0, chunk);
40+
api.methods.postLogs(data, success, shutdown);
4541
} else {
46-
sendingLogsInProgress = false;
47-
timeout = setTimeout(sendLogs, delay);
42+
// full batch is sent, set timeout for the next request
43+
if (cb) {
44+
// if exception is caught run next middleware or check if we need to shutdown the server
45+
cb();
46+
} else {
47+
sendingLogsInProgress = false;
48+
timeout = setTimeout(sendLogs, delay);
49+
}
4850
}
4951
}
5052
};

lib/sender.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports.send = function send(options, cb, fail) {
2626
}
2727
}
2828
} else {
29+
console.error(error.stack);
2930
logger.methods.push('error', error.message, [{error: error}]);
3031
}
3132
};

0 commit comments

Comments
 (0)