1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00
phorge-phorge/support/aphlict/server/lib/AphlictLog.js

62 lines
1.1 KiB
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,
_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');
}
},
},
});