Logger.with(properties: Record<string, unknown>): Logger
Get a logger with contextual properties. This is useful for log multiple messages with the shared set of properties.
const logger = getLogger("category"); const ctx = logger.with({ foo: 123, bar: "abc" }); ctx.info("A message with {foo} and {bar}."); ctx.warn("Another message with {foo}, {bar}, and {baz}.", { baz: true });
The above code is equivalent to:
const logger = getLogger("category"); logger.info("A message with {foo} and {bar}.", { foo: 123, bar: "abc" }); logger.warn( "Another message with {foo}, {bar}, and {baz}.", { foo: 123, bar: "abc", baz: true }, );
properties: Record<string, unknown>