json
Signature
Section titled “Signature”json(data: object, level: ZylogOutputLevel = 'info'): voidDescription
Section titled “Description”The json method stringifies any JavaScript object into a pretty-printed JSON format (2-space indentation). This ensures that complex data structures are readable in the terminal and correctly formatted for file logs.
Examples
Section titled “Examples”Logging a Payload
Section titled “Logging a Payload”Standard usage for inspecting incoming data.
const user = { id: 1, name: 'Alice', roles: ['admin', 'editor'] };
zylog.json(user);Critical Data Inspection
Section titled “Critical Data Inspection”Override the log level to ensure critical object state is captured in error logs.
try { processData();} catch (err) { zylog.json({ error: err.message, stack: err.stack }, 'error');}Using with Prefixes
Section titled “Using with Prefixes”Add context to your JSON dumps.
zylog.with({ prefix: 'CONFIG' }).json(process.env, 'debug');