Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/sails-hook-apianalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ module.exports = function sailsHookApiAnalytics(sails) {
//
var now = Date.now();
var MS_DEAD_AIR_BEFORE_NEW_LANDMARK = 30*1000;// 30 seconds
var MS_DEAD_AIR_BEFORE_WRITING_OUT_ENTIRE_TIMESTAMP = 2*60*60*1000;// 2 hours
var MS_DEAD_AIR_BEFORE_WRITING_OUT_ENTIRE_TIMESTAMP = 30*60*1000;// 30 minutes
var msSinceLastRequestReceived = now - sails.hooks.apianalytics._lastResponseFinishedAt;
var msSinceLastFullTimestamp = now - sails.hooks.apianalytics._lastFullTimestampAt;

// If this is the first request in a long while, then log an ENTIRE timestamp.
if (msSinceLastRequestReceived > MS_DEAD_AIR_BEFORE_WRITING_OUT_ENTIRE_TIMESTAMP) {
if (msSinceLastFullTimestamp > MS_DEAD_AIR_BEFORE_WRITING_OUT_ENTIRE_TIMESTAMP) {

logFn(
'\n' +
Expand All @@ -76,6 +77,7 @@ module.exports = function sailsHookApiAnalytics(sails) {
chalk.bold.underline(new Date(now)) + '\n' +
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - -' + '\n'
);
sails.hooks.apianalytics._lastFullTimestampAt = now;

}
// Check to see how long it's been since we finished handling the most recent request.
Expand Down Expand Up @@ -311,6 +313,7 @@ module.exports = function sailsHookApiAnalytics(sails) {
// this hook was initialized). We use this to be able to write
// date/time "landmarks" to the terminal.
sails.hooks.apianalytics._lastResponseFinishedAt = Date.now();
sails.hooks.apianalytics._lastFullTimestampAt = Date.now();

return next();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-hook-apianalytics",
"version": "2.0.3",
"version": "2.0.4",
"description": "Hook for advanced logging of API requests to a Sails.js server.",
"main": "lib/sails-hook-apianalytics.js",
"scripts": {
Expand Down