1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +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) { private function getStartCommand(array $server_argv) {
$launch_argv = array();
if ($this->debug) {
$launch_argv[] = '--debug=1';
}
return csprintf( return csprintf(
'%R %Ls -- %s %Ls', '%R %Ls -- %s %Ls %Ls',
$this->getNodeBinary(), $this->getNodeBinary(),
$this->getNodeArgv(), $this->getNodeArgv(),
$this->getAphlictScriptPath(), $this->getAphlictScriptPath(),
$launch_argv,
$server_argv); $server_argv);
} }

View file

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

View file

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

View file

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

View file

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