Zero‑dependency structured JSON logger for Node/Next.
// Source: https://github.com/melgarafael/DeskcommCRM | License: MIT | Copyright 2026 Rafael Melgaço
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Structured JSON logger (zero-deps, pino-style API).
*
* Used in API routes and workers. Output is one JSON line per call so log
* aggregators (Vercel runtime logs, Sentry breadcrumb sinks, etc.) can index
* arbitrary fields without parsing free-form strings.
*
* Never log secrets, raw tokens, message bodies, CPF, or phone numbers.
*/
export type LogContext = Record<string, unknown>;
function fmt(level: string, msg: string, ctx?: LogContext): string {
return JSON.stringify({
level,
msg,
ts: new Date().toISOString(),
...(ctx ?? {}),
});
}
export const logger = {
info(msg: string, ctx?: LogC
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key