express-zod-api icon indicating copy to clipboard operation
express-zod-api copied to clipboard

Built-in logger class with `.child()` method

Open RobinTail opened this issue 1 year ago • 1 comments
trafficstars

Can do this now (without additional libraries):

import { randomUUID } from "node:crypto";
import { BuiltinLogger, createConfig } from "express-zod-api";

declare module "express-zod-api" {
  interface LoggerOverrides extends BuiltinLogger {}
}

const config = createConfig({
  logger: { level: "debug", color: true },
  childLoggerProvider: ({ parent }) =>
    parent.child({ requestId: randomUUID() }), // context
});

requestId is special and displayed after the timestamp, looks this way:

Screenshot 2024-05-18 at 18 07 05

RobinTail avatar May 18 '24 16:05 RobinTail

Coverage Status

coverage: 100.0%. remained the same when pulling 7deff302735cbfc6e4d2931c90ea8f163a8ae2a8 on builtin-logger-class into ecda87453cb0c5177415912cd6302d5a362c4bdd on master.

coveralls-official[bot] avatar May 18 '24 16:05 coveralls-official[bot]