Files
web-check/api/_common/logger.js
Alicia Sykes 6ae6b25d45 fix: Vercel Node 20 deploy, and sec visibility
- Fixes Vercel deployment by pinning to 20.x
- Refactors console outputs into logger.js
- Fixes sections still visible when no data (Server Info)
- Fixes checks still show error after fallback succeeds (Screenshot)
- Updates client-side env var names, from `REACT_APP_` to `PUBLIC_`
2026-05-04 15:59:07 +01:00

28 lines
1.1 KiB
JavaScript

const LEVELS = { debug: 10, info: 20, warn: 30, error: 40, silent: 99 };
const THRESHOLD = LEVELS[(process.env.LOG_LEVEL || 'info').toLowerCase()] ?? LEVELS.info;
const fmt = (level, scope, msg, extra) => {
const ts = new Date().toISOString();
const tag = scope ? `[${scope}] ` : '';
const body = typeof msg === 'string' ? msg : JSON.stringify(msg);
const tail = extra === undefined
? ''
: ` ${typeof extra === 'string' ? extra : JSON.stringify(extra)}`;
return `${ts} ${level.toUpperCase().padEnd(5)} ${tag}${body}${tail}`;
};
const write = (level, stream, scope, msg, extra) => {
if (LEVELS[level] < THRESHOLD) return;
stream.write(fmt(level, scope, msg, extra) + '\n');
};
// Logger scoped to a route name; honours LOG_LEVEL env.
export const createLogger = (scope) => ({
debug: (msg, extra) => write('debug', process.stdout, scope, msg, extra),
info: (msg, extra) => write('info', process.stdout, scope, msg, extra),
warn: (msg, extra) => write('warn', process.stderr, scope, msg, extra),
error: (msg, extra) => write('error', process.stderr, scope, msg, extra),
});
export default createLogger;