Files
bare-operating-system/packages/bare-os-booter/lib/bare-os-host-booter-log.js
T
Raven Scott 7f4279d315 feat: POSIX/P2P roadmap — multisig shape, socket bridge, bin index, docs
- Unify pear.multisig.json validation via bare-os-protocol + kernel boot fragment
- Socket bridge: SCM_RIGHTS path, ancillary handling, TCP half-close/shutdown how,
  connect tcpRecvQueue + poll/recv EOF and EPIPE-shaped errors
- Bin manifest / Hyperbee hints schema 2 + namesDigest; batch-write invalidation
- Host booter structured logging; BOOT_PERF_DETAIL bare_stdlib_merge_ns timing
- Wasm kernel optional syscall imports; security_posture rotation hints schema 2
- Shell errexit inside compound bodies; expand getconf/_SC_* and bareOsGetconfSysconf
- Subprocess bridge snapshot timeoutPolicy; blind-relay protomux backpressure tests
- Pear updater minimal delegate example + verify-pear scan; holepunch drift repos
- Refresh handbook, kernel-image, syscall-socket-contract, posix matrix, PEAR-RUN

Rebuild coreutils/bundles; bundle kernel; keep seeder/kernel parity.
2026-04-05 02:08:38 -04:00

76 lines
2.3 KiB
JavaScript

/**
* Host-side booter diagnostics (runs before guest VFS exists).
* Avoids raw console.warn as the only sink; supports suppression and NDJSON file append.
*
* Env:
* - BARE_OS_HOST_BOOTER_LOG — `stderr` (default), `0`/`false`/`off` (silent), `ndjson` (append file)
* - BARE_OS_HOST_BOOTER_LOG_PATH — override path when mode is `ndjson` (default: ~/.bare-os/var/log/booter-host.ndjson)
*/
import fs from '#host-fs'
import path from '#host-path'
function hostDataRoot() {
const override =
globalThis.process?.env && globalThis.process.env.BARE_OS_HOST_DATA
if (override) return path.resolve(String(override))
const home =
(globalThis.process?.env && globalThis.process.env.HOME) || '/tmp'
return path.join(String(home), '.bare-os')
}
function defaultNdjsonPath() {
return path.join(hostDataRoot(), 'var', 'log', 'booter-host.ndjson')
}
/**
* @param {string} code Stable machine-readable code (e.g. ctx_bare_load_failed).
* @param {string} human Human-readable message (no secrets).
* @param {string} [detail] Optional short detail (error.message, etc.).
*/
export function bareOsHostBooterWarn(code, human, detail) {
const env = globalThis.process?.env || {}
const mode = String(env.BARE_OS_HOST_BOOTER_LOG || 'stderr')
.trim()
.toLowerCase()
if (
mode === '0' ||
mode === 'false' ||
mode === 'off' ||
mode === 'no' ||
mode === 'silent'
) {
return
}
const d = detail != null ? String(detail).slice(0, 4000) : ''
const line = `[bare-os-booter][${code}] ${human}${d ? `: ${d}` : ''}`
if (mode === 'ndjson') {
const logPath = String(env.BARE_OS_HOST_BOOTER_LOG_PATH || '').trim() || defaultNdjsonPath()
try {
fs.mkdirSync(path.dirname(logPath), { recursive: true })
fs.appendFileSync(
logPath,
`${JSON.stringify({
type: 'booterHostWarn',
code: String(code).slice(0, 128),
message: String(human).slice(0, 2000),
detail: d || undefined,
ts: Date.now()
})}\n`,
'utf8'
)
} catch {
/* fall through to stderr */
}
}
if (mode === 'ndjson' && env.BARE_OS_HOST_BOOTER_LOG_STDERR !== '1') {
return
}
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
console.warn(line)
}
}