1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 17:22:42 +01:00
phorge-phorge/support/aphlict/server/lib/AphlictLog.js

48 lines
935 B
JavaScript
Raw Normal View History

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