Harden server logging and production boot experience
CI / test (push) Has been cancelled

Replace ad-hoc console output with a structured logger (pretty/JSON,
levels, redaction, optional file rotation), a clean startup banner with
Docker/feature probes, graceful shutdown signals, and slow-RPC warnings.
This commit is contained in:
2026-07-10 23:59:13 -04:00
parent d87e6fe486
commit fa99bd8c6e
7 changed files with 482 additions and 143 deletions
+7 -2
View File
@@ -9,9 +9,12 @@ import DHT from 'hyperdht'
import b4a from 'b4a'
import crypto from 'hypercore-crypto'
import dotenv from 'dotenv'
import logger from '../utils/logger.js'
dotenv.config()
const log = logger.child('keys')
/**
* @param {string} [envPath]
* @returns {{ seed: Uint8Array, keyPair: { publicKey: Uint8Array, secretKey: Uint8Array }, publicKeyHex: string, seedHex: string }}
@@ -26,7 +29,9 @@ export function loadOrCreateKeyPair(envPath = '.env') {
const publicKeyHex = b4a.toString(DHT.keyPair(seed).publicKey, 'hex')
const line = `\nSERVER_SEED=${seedHex}\nSERVER_PUBLIC_KEY=${publicKeyHex}\n`
fs.appendFileSync(envPath, line, { flag: 'a' })
console.log('[INFO] Generated new SERVER_SEED and SERVER_PUBLIC_KEY in', path.resolve(envPath))
log.info('Generated new SERVER_SEED and SERVER_PUBLIC_KEY', {
path: path.resolve(envPath),
})
}
if (!/^[0-9a-fA-F]{64}$/.test(seedHex)) {
@@ -54,7 +59,7 @@ export function loadOrCreateKeyPair(envPath = '.env') {
}
fs.writeFileSync(envPath, env)
} catch (err) {
console.warn('[WARN] Could not update .env with SERVER_PUBLIC_KEY:', err.message)
log.warn('Could not update .env with SERVER_PUBLIC_KEY', { error: err.message })
}
}
+9 -1
View File
@@ -1,6 +1,10 @@
/**
* Tracks live ProtomuxRPC sessions for broadcast and cleanup.
*/
import logger from '../utils/logger.js'
const log = logger.child('peers')
export class PeerRegistry {
constructor() {
/** @type {Map<string, import('../rpc/session.js').PeerSession>} */
@@ -46,7 +50,11 @@ export class PeerRegistry {
try {
session.push(method, payload)
} catch (err) {
console.error(`[ERROR] Broadcast to ${session.id.slice(0, 12)} failed: ${err.message}`)
log.debug('Broadcast failed', {
peerId: session.id.slice(0, 12),
method,
error: err.message,
})
}
}
}