Files
holesail-browser/native-host/host/logger.js
T
Raven Scott 15caac7032
CI / Build & Test (push) Successful in 2m46s
refactor(native-host): modularize host.js and holesail-manager.js
Split host.js (435 lines) into host/{paths,logger,startup,message-router}.js.
Split holesail-manager.js (698 lines) into holesail-manager/{state,settings,
connections,port-allocator,servers,virtual-hosts,service-tunnels,index}.js.

Top-level host.js and holesail-manager.js become thin shims so index.mjs
requires no changes. Deleted dev scratch file test-cp.mjs.

Updated CI with 12 new node --check lines for all sub-modules.
Updated docs/ARCHITECTURE.md with per-file tables for host/ and
holesail-manager/ sub-modules.

No functionality changed. No new dependencies.
2026-02-28 23:15:08 -05:00

48 lines
1.4 KiB
JavaScript

/**
* File-based logging for the native host.
* Writes timestamped lines to holesail-browser.log (or BRIDGE_SWARM_LOG override)
* and to process.stderr for native messaging host visibility.
*/
const path = require('bare-path');
const fs = require('bare-fs');
const { BASE_DIR } = require('./paths.js');
const DEBUG = process.env.HOLESAIL_DEBUG === '1' || process.env.HOLESAIL_DEBUG === 'true';
const LOG_FILE = path.join(BASE_DIR, 'holesail-browser.log');
let logStream = null;
function getLogStream() {
if (!logStream) {
try {
const logPath = process.env.BRIDGE_SWARM_LOG || LOG_FILE;
logStream = fs.createWriteStream(logPath, { flags: 'a' });
} catch (e) {
return null;
}
}
return logStream;
}
function log(...args) {
const stream = getLogStream();
if (stream) {
const msg = '[' + new Date().toISOString() + '] ' + args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ') + '\n';
stream.write(msg);
}
if (process.stderr) {
process.stderr.write('[' + new Date().toISOString() + '] ' + args.join(' ') + '\n');
}
}
function debugLog(...args) {
if (!DEBUG) return;
const msg = '[host:debug] ' + args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ');
if (process.stderr) process.stderr.write(msg + '\n');
const stream = getLogStream();
if (stream) stream.write('[' + new Date().toISOString() + '] ' + msg + '\n');
}
module.exports = { log, debugLog };