mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-29 08:50:58 +01:00
28fe44da0a
Summary: Ref T4324. - Create `Listener` to represent listening clients. - Create `ListenerList` to represent the current list of clients. - Create `Logfile` to handle logging. Test Plan: Clicked "Send Test Notification", verified logs, status and notifications all work correctly. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4324 Differential Revision: https://secure.phabricator.com/D8256
52 lines
1 KiB
JavaScript
52 lines
1 KiB
JavaScript
var JX = require('javelin').JX;
|
|
|
|
var fs = require('fs');
|
|
var util = require('util');
|
|
|
|
JX.install('AphlictLog', {
|
|
construct : function() {
|
|
this._writeToLogs = [];
|
|
this._writeToConsoles = [];
|
|
},
|
|
|
|
members : {
|
|
_writeToConsoles : null,
|
|
_writeToLogs : null,
|
|
|
|
addLogfile : function(path) {
|
|
var options = {
|
|
flags: 'a',
|
|
encoding: 'utf8',
|
|
mode: 066
|
|
};
|
|
|
|
var logfile = fs.createWriteSteam(path, options);
|
|
|
|
this._writeToLogs.push(logfile);
|
|
|
|
return this;
|
|
},
|
|
|
|
addConsole : function(console) {
|
|
this._writeToConsoles.push(console);
|
|
return this;
|
|
},
|
|
|
|
log : function(pattern) {
|
|
var str = util.format.apply(null, arguments);
|
|
var date = new Date().toLocaleString();
|
|
str = '[' + date + '] ' + str;
|
|
|
|
var ii;
|
|
for (ii = 0; ii < this._writeToConsoles.length; ii++) {
|
|
this._writeToConsoles[ii].log(str);
|
|
}
|
|
|
|
for (ii = 0; ii < this._writeToLogs.length; ii++) {
|
|
this._writeToLogs[ii].write(str + "\n");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
});
|