@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1'use strict';
2
3var JX = require('./javelin').JX;
4
5var fs = require('fs');
6var util = require('util');
7
8JX.install('AphlictLog', {
9 construct: function() {
10 this._consoles = [];
11 this._logs = [];
12 },
13
14 members: {
15 _consoles: null,
16 _logs: null,
17 _trace: null,
18
19 setTrace: function(trace) {
20 this._trace = trace;
21 return this;
22 },
23
24 addConsole: function(console) {
25 this._consoles.push(console);
26 return this;
27 },
28
29 addLog: function(path) {
30 this._logs.push(fs.createWriteStream(path, {
31 flags: 'a',
32 encoding: 'utf8',
33 mode: '0664',
34 }));
35 return this;
36 },
37
38 trace: function() {
39 if (!this._trace) {
40 return;
41 }
42
43 return this.log.apply(this, arguments);
44 },
45
46 log: function() {
47 var str = util.format.apply(null, arguments);
48 var date = new Date().toLocaleString();
49 str = '[' + date + '] ' + str;
50
51 var ii;
52 for (ii = 0; ii < this._consoles.length; ii++) {
53 this._consoles[ii].log(str);
54 }
55
56 for (ii = 0; ii < this._logs.length; ii++) {
57 this._logs[ii].write(str + '\n');
58 }
59 },
60 },
61});