Skip to content
Warlock.js v4

JSON File Channel

JSONFileLog is a drop-in replacement for FileLog that writes structured JSON instead of plain text. Every entry is a typed object — no regex parsing at query time.

import { JSONFileLog } from "@warlock.js/logger";
const channel = new JSONFileLog({
storagePath: process.cwd() + "/storage/logs",
chunk: "daily",
});

The extension is always json, regardless of the extension option. Each file is a JSON object with a messages array:

{
"messages": [
{
"content": "New user created",
"level": "info",
"date": "15-03-2024 10:22:01",
"module": "users",
"action": "register"
},
{
"content": "Card declined",
"level": "error",
"date": "15-03-2024 10:22:03",
"module": "payments",
"action": "charge",
"stack": [
"Error: Card declined",
" at chargeCard (/app/src/payments.ts:42:11)",
" at processTicksAndRejections (node:internal/process/task_queues:95:5)"
]
}
]
}
AspectFileLogJSONFileLog
Output formatPlain-text linesJSON object with messages array
Error stackRaw multi-line string after [trace]Split on newlines, stored as string[] in stack
Message fieldPre-formatted log linecontent field holds the original string
File extensionConfigurable (default "log")Always "json"

It inherits every FileLog option and supports the same chunking, rotation, and groupBy features.

JSONFileLog writes through safe-stable-stringify (the same library Pino and Winston use), so the context payload can carry shapes that would otherwise throw in JSON.stringify:

ShapeSerialized as
Circular referencehandled (no throw)
BigIntstringified value
Function / symboldropped (standard JSON behavior)
Error (top-level or nested in context){ name, message, stack, ...enumerableProps }
Class instanceenumerable own properties — same as default JSON

The channel does not tag class instances with their class name. If you need a specific shape, pre-shape the value before passing it to context:

await log.error("orders", "checkout", "Card declined", {
order: { id: order.id, status: order.status }, // not the full Order instance
declineReason,
});