1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00
phorge-phorge/support/aphlict/server/lib/AphlictLog.js
Joshua Spence 7304e29dec Various minor JSHint fixes.
Summary: Various fixes as suggested by JSHint.

Test Plan: Eye-balled it.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9783
2014-07-01 06:00:12 +10:00

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() {
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');
}
}
}
});