-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitTrack.js
More file actions
65 lines (54 loc) · 2.38 KB
/
Copy pathBitTrack.js
File metadata and controls
65 lines (54 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* BitTrack — unified entry point
* Runs the web panel (panel.js) and the monitor (monitor.js) in the same process.
*
* Usage: node BitTrack.js
*/
'use strict';
const path = require('path');
// ─── UNIFIED LOGGING ──────────────────────────────────────────────────────────
// Prefixes each line with a tag identifying the source: [PANEL] or [MONITOR]
// Preserves colors and emojis from the original loggers.
function patchConsole(tag) {
const PAD = 9; // fixed tag width to align columns
const label = `[${tag}]`.padEnd(PAD);
const wrap = (original) => (...args) => {
// If the first argument already contains the monitor timestamp ([YYYY-MM-DD...])
// insert the tag right after the timestamp to preserve the format.
if (typeof args[0] === 'string' && args[0].startsWith('[')) {
const first = args[0];
const rest = args.slice(1);
// e.g. "[2026-03-19 15:00:00] ℹ️ " → "[2026-03-19 15:00:00] [MONITOR] ℹ️ "
const patched = first.replace(/^(\[\d{2}[\-\/]\d{2}[\-\/]\d{4}[,\s]+\d{2}:\d{2}:\d{2}\])\s*/, `$1 ${label} `);
original(patched, ...rest);
} else {
original(`${label}`, ...args);
}
};
return {
log: wrap(console._log || console.log),
warn: wrap(console._warn || console.warn),
error: wrap(console._error || console.error),
};
}
// Save originals before any patching
console._log = console.log.bind(console);
console._warn = console.warn.bind(console);
console._error = console.error.bind(console);
// ─── START PANEL ──────────────────────────────────────────────────────────────
;(() => {
const p = patchConsole('PANEL');
// Temporarily override console while panel.js is loaded
console.log = p.log;
console.warn = p.warn;
console.error = p.error;
require('./panel.js');
})();
// ─── START MONITOR ────────────────────────────────────────────────────────────
;(() => {
const m = patchConsole('MONITOR');
console.log = m.log;
console.warn = m.warn;
console.error = m.error;
require('./monitor.js');
})();