Skip to content

@gvray/logger


@gvray/logger / jsonMiddleware

Function: jsonMiddleware() ​

jsonMiddleware(): LogMiddleware

Defined in: middleware/json.ts:21

Middleware that serializes each log entry as a single JSON string.

The resulting object contains timestamp, level, namespace, and message (args joined into a single string). Useful when you want structured, parseable output for debugging or for feeding into another in-process tool. Recommended with colors: false to keep the payload clean.

Returns ​

LogMiddleware

A LogMiddleware instance.

Example ​

ts
const logger = new Logger({ colors: false });
logger.use(jsonMiddleware());
logger.info('login', { userId: 123 });
// {"timestamp":"2026-...","level":"INFO","namespace":null,"message":"login {\"userId\":123}"}

Released under the MIT License.