1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00

Reduce the verbosity of the "Aphlict" log

Summary:
See PHI1692. Currently, the Aphlict log is ridiculously verbose. As an initial pass at improving this:

  - When starting in "debug" mode, pass "--debug=1" to Node.
  - In Node, separate logging into "log" (lower-volume, more-important messages) and "trace" (higher-volume, less-important messages).
  - Only print "trace" messages in "debug" mode.

Test Plan: Ran Aphlict in debug and non-debug modes. Behavior unchanged in debug mode, but log has more sensible verbosity in non-debug mode.

Differential Revision: https://secure.phabricator.com/D21115
This commit is contained in:
epriestley 2020-04-14 13:17:41 -07:00
parent 59c855276b
commit 99cbc20778
5 changed files with 70 additions and 17 deletions

View file

@ -550,11 +550,18 @@ abstract class PhabricatorAphlictManagementWorkflow
}
private function getStartCommand(array $server_argv) {
$launch_argv = array();
if ($this->debug) {
$launch_argv[] = '--debug=1';
}
return csprintf(
'%R %Ls -- %s %Ls',
'%R %Ls -- %s %Ls %Ls',
$this->getNodeBinary(),
$this->getNodeArgv(),
$this->getAphlictScriptPath(),
$launch_argv,
$server_argv);
}

View file

@ -9,6 +9,7 @@ var fs = require('fs');
function parse_command_line_arguments(argv) {
var args = {
test: false,
debug: false,
config: null
};
@ -34,12 +35,16 @@ function parse_config(args) {
require('./lib/AphlictLog');
var debug = new JX.AphlictLog()
.addConsole(console);
var debug = new JX.AphlictLog();
var args = parse_command_line_arguments(process.argv);
var config = parse_config(args);
if (args.test || args.debug) {
debug.addConsole(console);
debug.setTrace(true);
}
function set_exit_code(code) {
process.on('exit', function() {
process.exit(code);

View file

@ -4,7 +4,6 @@ var JX = require('./javelin').JX;
require('./AphlictListenerList');
var http = require('http');
var url = require('url');
JX.install('AphlictAdminServer', {
@ -54,6 +53,17 @@ JX.install('AphlictAdminServer', {
return this;
},
trace: function() {
var logger = this.getLogger();
if (!logger) {
return;
}
logger.trace.apply(logger, arguments);
return this;
},
listen: function() {
return this._server.listen.apply(this._server, arguments);
},
@ -76,7 +86,7 @@ JX.install('AphlictAdminServer', {
try {
var msg = JSON.parse(body);
self.log(
self.trace(
'Received notification (' + instance + '): ' +
JSON.stringify(msg));
++self._messagesIn;
@ -201,13 +211,13 @@ JX.install('AphlictAdminServer', {
listener.writeMessage(message);
++this._messagesOut;
this.log(
this.trace(
'<%s> Wrote Message',
listener.getDescription());
} catch (error) {
list.removeListener(listener);
this.log(
this.trace(
'<%s> Write Error: %s',
listener.getDescription(),
error);

View file

@ -3,7 +3,6 @@
var JX = require('./javelin').JX;
require('./AphlictListenerList');
require('./AphlictLog');
var url = require('url');
var util = require('util');
@ -60,6 +59,17 @@ JX.install('AphlictClientServer', {
return this;
},
trace: function() {
var logger = this.getLogger();
if (!logger) {
return;
}
logger.trace.apply(logger, arguments);
return this;
},
_onrequest: function(request, response) {
// The websocket code upgrades connections before they get here, so
// this only handles normal HTTP connections. We just fail them with
@ -104,17 +114,24 @@ JX.install('AphlictClientServer', {
var listener = self.getListenerList(instance).addListener(ws);
function log() {
self.log(
util.format('<%s>', listener.getDescription()) +
function msg(argv) {
return util.format('<%s>', listener.getDescription()) +
' ' +
util.format.apply(null, arguments));
util.format.apply(null, argv);
}
log('Connected from %s.', ws._socket.remoteAddress);
function log() {
self.log(msg(arguments));
}
function trace() {
self.trace(msg(arguments));
}
trace('Connected from %s.', ws._socket.remoteAddress);
ws.on('message', function(data) {
log('Received message: %s', data);
trace('Received message: %s', data);
var message;
try {
@ -126,14 +143,14 @@ JX.install('AphlictClientServer', {
switch (message.command) {
case 'subscribe':
log(
trace(
'Subscribed to: %s',
JSON.stringify(message.data));
listener.subscribe(message.data);
break;
case 'unsubscribe':
log(
trace(
'Unsubscribed from: %s',
JSON.stringify(message.data));
listener.unsubscribe(message.data);
@ -180,7 +197,7 @@ JX.install('AphlictClientServer', {
ws.on('close', function() {
self.getListenerList(instance).removeListener(listener);
log('Disconnected.');
trace('Disconnected.');
});
});

View file

@ -14,6 +14,12 @@ JX.install('AphlictLog', {
members: {
_consoles: null,
_logs: null,
_trace: null,
setTrace: function(trace) {
this._trace = trace;
return this;
},
addConsole: function(console) {
this._consoles.push(console);
@ -29,6 +35,14 @@ JX.install('AphlictLog', {
return this;
},
trace: function() {
if (!this._trace) {
return;
}
return this.log.apply(this, arguments);
},
log: function() {
var str = util.format.apply(null, arguments);
var date = new Date().toLocaleString();