1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00
phorge-phorge/support/aphlict/server/lib/AphlictLog.js
epriestley 99cbc20778 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
2020-04-14 13:24:44 -07:00

61 lines
1.1 KiB
JavaScript

'use strict';
var JX = require('./javelin').JX;
var fs = require('fs');
var util = require('util');
JX.install('AphlictLog', {
construct: function() {
this._consoles = [];
this._logs = [];
},
members: {
_consoles: null,
_logs: null,
_trace: null,
setTrace: function(trace) {
this._trace = trace;
return this;
},
addConsole: function(console) {
this._consoles.push(console);
return this;
},
addLog: function(path) {
this._logs.push(fs.createWriteStream(path, {
flags: 'a',
encoding: 'utf8',
mode: '0664',
}));
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();
str = '[' + date + '] ' + str;
var ii;
for (ii = 0; ii < this._consoles.length; ii++) {
this._consoles[ii].log(str);
}
for (ii = 0; ii < this._logs.length; ii++) {
this._logs[ii].write(str + '\n');
}
},
},
});