Files
miles c250653961 Add comprehensive test suite for application functionality
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers.
- Create configuration tests to validate loading of defaults and environment overrides.
- Add tests for FEDL service to verify data handling and snapshot functionality.
- Introduce GitHub service tests to check API data normalization and caching behavior.
- Develop monitor service tests for network checks and uptime calculations.
- Implement persistence tests to ensure database migrations are idempotent and data persists across restarts.
- Add vault service tests for session management and brute-force protection mechanisms.
- Include helper functions for test context creation and JSON response handling.
2026-11-08 16:24:06 -06:00

39 lines
1.3 KiB
JavaScript

const LEVELS = { error: 0, warn: 1, info: 2, debug: 3 };
export function createLogger({ level = 'info', name = 'dashboard' } = {}) {
const threshold = LEVELS[level] ?? LEVELS.info;
function write(lvl, message, fields = {}) {
if ((LEVELS[lvl] ?? LEVELS.info) > threshold) return;
const entry = {
ts: new Date().toISOString(),
level: lvl,
logger: name,
msg: message,
...fields
};
const line = JSON.stringify(entry);
if (lvl === 'error' || lvl === 'warn') process.stderr.write(line + '\n');
else process.stdout.write(line + '\n');
}
return {
level,
error: (msg, fields) => write('error', msg, fields),
warn: (msg, fields) => write('warn', msg, fields),
info: (msg, fields) => write('info', msg, fields),
debug: (msg, fields) => write('debug', msg, fields),
child: (fields) => {
const parent = createLogger({ level, name });
return {
...parent,
error: (msg, f = {}) => parent.error(msg, { ...fields, ...f }),
warn: (msg, f = {}) => parent.warn(msg, { ...fields, ...f }),
info: (msg, f = {}) => parent.info(msg, { ...fields, ...f }),
debug: (msg, f = {}) => parent.debug(msg, { ...fields, ...f }),
child: parent.child
};
}
};
}