mirror of
https://github.com/Lissy93/web-check.git
synced 2026-05-13 06:01:02 -04:00
- Sitemap endpoint now recursively expands sitemap-index files - Fixes #165 - Strips :port from target URLs in get-ip, dns, dns-server, ports, mail-config - Fixes #203 - Configurable trust proxy (TRUST_PROXY env) so app works behind Traefik/nginx - Fixes #157 - Tranco rank now correctly says "top 1 million" (was "100 million") - Fixes #257 - Adds engines.node ">=20" so Vercel picks a supported runtime - Re #212 - Raises Vercel maxDuration from 10s to 60s, cutting most 504 timeouts - Re #251 - Re #287 - Bumps axios 1.4.8 to 1.16, closing 4 high-severity SSRF/DoS CVEs - Re #289 - Fixes mail-config crash where dns module was awaited as if promise-based - Adds reusable structured logging util for the API - Bumps a whole bunch of deps, and resolves lots of open npm CVEs
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
// Lightweight structured logger. Honours LOG_LEVEL env (debug, info, warn, error, silent).
|
|
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');
|
|
};
|
|
|
|
// Returns a logger pinned to a scope (e.g. an API route name).
|
|
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;
|