Skip to content

Commit

Permalink
fix(logreport): log filled report
Browse files Browse the repository at this point in the history
  • Loading branch information
tarotlwei committed Jul 30, 2018
1 parent 8379998 commit ceaa05e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions bin/proxy/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function bind_listen(server) {

req.removeAllListeners('fail');
req.removeAllListeners('reportLog');
req.removeAllListeners('logFilled');

if (d.currentContext) {
d.currentContext.window.websocket = null;
Expand Down Expand Up @@ -264,6 +265,11 @@ function bind_listen(server) {

logReport();
reportWebSocketLog(ws);

req.on('logFilled', function() {
logReport.reportLog();
logger.clean();
});
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions bin/tsw/util/auto-report/logReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ module.exports = function(req, res) {

req.removeAllListeners('reportLog');
req.once('reportLog', function() {
reportLog();
this.removeAllListeners('reportLogStream', reportLog);
module.exports.reportLog();
this.removeAllListeners('reportLogStream', module.exports.reportLog);
});
req.on('reportLogStream', reportLog);
req.on('reportLogStream', module.exports.reportLog);
};

module.exports.fingureCroup = function(opts) {
Expand Down Expand Up @@ -529,7 +529,7 @@ module.exports.top100 = function(req, res) {

};

function reportLog() {
module.exports.reportLog = function() {
const window = context.window || {};
const isWebSocket = !!window.websocket;
const req = window.request;
Expand Down
21 changes: 21 additions & 0 deletions bin/tsw/util/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ Logger.prototype = {
contextMod.currentContext().log = null;
},

clean: function() {
let log = this.getLog();
log.arr = null;
if (log.json) {
log.json.curr = null;
log.json.ajax = null;
log.json = null;
}
log = null;
},

getJson: function(cleared) {
const log = this.getLog();
let json = {
Expand Down Expand Up @@ -243,6 +254,16 @@ Logger.prototype = {
log[type] = 1;
}
}

if (log.arr.length > 1000 || (log.json && log.json.ajax && log.json.ajax.length > 30)) {
if (!contextMod.currentContext().emitLogFilled) {
contextMod.currentContext().emitLogFilled = true;
window && window.request && window.request.emit('logFilled');
setTimeout(function() {
contextMod.currentContext().emitLogFilled = false;
}, 1000);
}
}
}
},

Expand Down

0 comments on commit ceaa05e

Please sign in to comment.