@logtape/logtape 1.1.0-dev.337 → 1.1.0-dev.338

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.1.0-dev.337+e8eb9c7d",
3
+ "version": "1.1.0-dev.338+557a49e7",
4
4
  "license": "MIT",
5
5
  "exports": "./src/mod.ts",
6
6
  "imports": {
package/dist/logger.cjs CHANGED
@@ -95,18 +95,22 @@ var LoggerImpl = class LoggerImpl {
95
95
  for (const sink of this.sinks) yield sink;
96
96
  }
97
97
  emit(record, bypassSinks) {
98
- if (this.lowestLevel === null || require_level.compareLogLevel(record.level, this.lowestLevel) < 0 || !this.filter(record)) return;
99
- for (const sink of this.getSinks(record.level)) {
98
+ const fullRecord = "category" in record ? record : {
99
+ ...record,
100
+ category: this.category
101
+ };
102
+ if (this.lowestLevel === null || require_level.compareLogLevel(fullRecord.level, this.lowestLevel) < 0 || !this.filter(fullRecord)) return;
103
+ for (const sink of this.getSinks(fullRecord.level)) {
100
104
  if (bypassSinks?.has(sink)) continue;
101
105
  try {
102
- sink(record);
106
+ sink(fullRecord);
103
107
  } catch (error) {
104
108
  const bypassSinks2 = new Set(bypassSinks);
105
109
  bypassSinks2.add(sink);
106
110
  metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", {
107
111
  sink,
108
112
  error,
109
- record
113
+ record: fullRecord
110
114
  }, bypassSinks2);
111
115
  }
112
116
  }
@@ -271,6 +275,16 @@ var LoggerCtx = class LoggerCtx {
271
275
  logTemplate(level, messageTemplate, values) {
272
276
  this.logger.logTemplate(level, messageTemplate, values, this.properties);
273
277
  }
278
+ emit(record) {
279
+ const recordWithContext = {
280
+ ...record,
281
+ properties: {
282
+ ...this.properties,
283
+ ...record.properties
284
+ }
285
+ };
286
+ this.logger.emit(recordWithContext);
287
+ }
274
288
  trace(message, ...values) {
275
289
  if (typeof message === "string") this.log("trace", message, values[0] ?? {});
276
290
  else if (typeof message === "function") this.logLazily("trace", message);
package/dist/logger.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { LogRecord } from "./record.cjs";
2
+
1
3
  //#region src/logger.d.ts
2
4
 
3
5
  /**
@@ -627,6 +629,36 @@ interface Logger {
627
629
  * @throws {TypeError} If no log record was made inside the callback.
628
630
  */
629
631
  fatal(callback: LogCallback): void;
632
+ /**
633
+ * Emits a log record with custom fields while using this logger's
634
+ * category.
635
+ *
636
+ * This is a low-level API for integration scenarios where you need full
637
+ * control over the log record, particularly for preserving timestamps
638
+ * from external systems.
639
+ *
640
+ * ```typescript
641
+ * const logger = getLogger(["my-app", "integration"]);
642
+ *
643
+ * // Emit a log with a custom timestamp
644
+ * logger.emit({
645
+ * timestamp: kafkaLog.originalTimestamp,
646
+ * level: "info",
647
+ * message: [kafkaLog.message],
648
+ * rawMessage: kafkaLog.message,
649
+ * properties: {
650
+ * source: "kafka",
651
+ * partition: kafkaLog.partition,
652
+ * offset: kafkaLog.offset,
653
+ * },
654
+ * });
655
+ * ```
656
+ *
657
+ * @param record Log record without category field (category comes from
658
+ * the logger instance)
659
+ * @since 1.1.0
660
+ */
661
+ emit(record: Omit<LogRecord, "category">): void;
630
662
  }
631
663
  /**
632
664
  * A logging callback function. It is used to defer the computation of a
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;AAqSkD,UAjRjC,MAAA,CAiRiC;EAAM;;;EA0DpB,SA4BnB,QAAA,EAAA,SAAA,MAAA,EAAA;EAAM;;;;EA2DgB,SA6BtB,MAAA,EArbE,MAqbF,GAAA,IAAA;EAAM;;;;;;;;;;;;;AA2NM;AAS7B;AASA;AASA;;EAA0B,QAOb,CAAA,WAAA,EAAA,MAAA,GAAA,SAAA,CAAA,MAAA,CAAA,GAAA,SAAA,CAAA,MAAA,EAAA,GAAA,MAA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kBAcF;;;;;;;;;;;iBAYD;;;;;;;;;;;;;;;;;;;;;;;;;sCA4BA,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAgC9B;;;;;;;;;;;;;kBAcF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+BH,KAAK;;;;;;;;KASR,WAAA,YAAuB;;;;;;;;KASvB,iBAAA,aACD;;;;;UAQM,SAAA;;;;;;YAOJ;;;;;;;;;;iCAeI,iCAAiC;;;;;;eAQnC;;;;;;aAOF;;;;;;;;;;;;;;iBAeG,SAAA,yCAAsD"}
package/dist/logger.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { LogRecord } from "./record.js";
2
+
1
3
  //#region src/logger.d.ts
2
4
 
3
5
  /**
@@ -627,6 +629,36 @@ interface Logger {
627
629
  * @throws {TypeError} If no log record was made inside the callback.
628
630
  */
629
631
  fatal(callback: LogCallback): void;
632
+ /**
633
+ * Emits a log record with custom fields while using this logger's
634
+ * category.
635
+ *
636
+ * This is a low-level API for integration scenarios where you need full
637
+ * control over the log record, particularly for preserving timestamps
638
+ * from external systems.
639
+ *
640
+ * ```typescript
641
+ * const logger = getLogger(["my-app", "integration"]);
642
+ *
643
+ * // Emit a log with a custom timestamp
644
+ * logger.emit({
645
+ * timestamp: kafkaLog.originalTimestamp,
646
+ * level: "info",
647
+ * message: [kafkaLog.message],
648
+ * rawMessage: kafkaLog.message,
649
+ * properties: {
650
+ * source: "kafka",
651
+ * partition: kafkaLog.partition,
652
+ * offset: kafkaLog.offset,
653
+ * },
654
+ * });
655
+ * ```
656
+ *
657
+ * @param record Log record without category field (category comes from
658
+ * the logger instance)
659
+ * @since 1.1.0
660
+ */
661
+ emit(record: Omit<LogRecord, "category">): void;
630
662
  }
631
663
  /**
632
664
  * A logging callback function. It is used to defer the computation of a
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;AAqSkD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mBAgC/B;;;;;;;;;;;;;iBAcF;;;;;;;;;;;;mBAaE;;;;;;;;;;;;;;;;;;;;;;;;;;wCA6BF,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAgC5B;;;;;;;;;;;;;;oBAeF;;;;;;;;;;;iBAYH;;;;;;;;;;;;;;;;;;;;;;;;;sCA4BA,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAgC9B;;;;;;;;;;;;;kBAcF;;;;;;;;;;;iBAYD;;;;;;;;;;;;;;;;;;;;;;;;;sCA4BA,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAgC9B;;;;;;;;;;;;;kBAcF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+BH,KAAK;;;;;;;;KASR,WAAA,YAAuB;;;;;;;;KASvB,iBAAA,aACD;;;;;UAQM,SAAA;;;;;;YAOJ;;;;;;;;;;iCAeI,iCAAiC;;;;;;eAQnC;;;;;;aAOF;;;;;;;;;;;;;;iBAeG,SAAA,yCAAsD"}
package/dist/logger.js CHANGED
@@ -95,18 +95,22 @@ var LoggerImpl = class LoggerImpl {
95
95
  for (const sink of this.sinks) yield sink;
96
96
  }
97
97
  emit(record, bypassSinks) {
98
- if (this.lowestLevel === null || compareLogLevel(record.level, this.lowestLevel) < 0 || !this.filter(record)) return;
99
- for (const sink of this.getSinks(record.level)) {
98
+ const fullRecord = "category" in record ? record : {
99
+ ...record,
100
+ category: this.category
101
+ };
102
+ if (this.lowestLevel === null || compareLogLevel(fullRecord.level, this.lowestLevel) < 0 || !this.filter(fullRecord)) return;
103
+ for (const sink of this.getSinks(fullRecord.level)) {
100
104
  if (bypassSinks?.has(sink)) continue;
101
105
  try {
102
- sink(record);
106
+ sink(fullRecord);
103
107
  } catch (error) {
104
108
  const bypassSinks2 = new Set(bypassSinks);
105
109
  bypassSinks2.add(sink);
106
110
  metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", {
107
111
  sink,
108
112
  error,
109
- record
113
+ record: fullRecord
110
114
  }, bypassSinks2);
111
115
  }
112
116
  }
@@ -271,6 +275,16 @@ var LoggerCtx = class LoggerCtx {
271
275
  logTemplate(level, messageTemplate, values) {
272
276
  this.logger.logTemplate(level, messageTemplate, values, this.properties);
273
277
  }
278
+ emit(record) {
279
+ const recordWithContext = {
280
+ ...record,
281
+ properties: {
282
+ ...this.properties,
283
+ ...record.properties
284
+ }
285
+ };
286
+ this.logger.emit(recordWithContext);
287
+ }
274
288
  trace(message, ...values) {
275
289
  if (typeof message === "string") this.log("trace", message, values[0] ?? {});
276
290
  else if (typeof message === "function") this.logLazily("trace", message);
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","names":["category: string | readonly string[]","rootLogger: LoggerImpl | null","parent: LoggerImpl | null","category: readonly string[]","subcategory:\n | string\n | readonly [string]\n | readonly [string, ...(readonly string[])]","child: LoggerImpl | undefined","properties: Record<string, unknown>","record: LogRecord","level: LogLevel","bypassSinks?: Set<Sink>","rawMessage: string","properties: Record<string, unknown> | (() => Record<string, unknown>)","cachedProps: Record<string, unknown> | undefined","callback: LogCallback","rawMessage: TemplateStringsArray | undefined","msg: unknown[] | undefined","messageTemplate: TemplateStringsArray","values: unknown[]","message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>","logger: LoggerImpl","subcategory: string | readonly [string] | readonly [string, ...string[]]","message: string","template: string","message: unknown[]","prop: unknown","template: TemplateStringsArray","values: readonly unknown[]"],"sources":["../src/logger.ts"],"sourcesContent":["import type { ContextLocalStorage } from \"./context.ts\";\nimport type { Filter } from \"./filter.ts\";\nimport { compareLogLevel, type LogLevel } from \"./level.ts\";\nimport type { LogRecord } from \"./record.ts\";\nimport type { Sink } from \"./sink.ts\";\n\n/**\n * A logger interface. It provides methods to log messages at different\n * severity levels.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * logger.trace `A trace message with ${value}`\n * logger.debug `A debug message with ${value}.`;\n * logger.info `An info message with ${value}.`;\n * logger.warn `A warning message with ${value}.`;\n * logger.error `An error message with ${value}.`;\n * logger.fatal `A fatal error message with ${value}.`;\n * ```\n */\nexport interface Logger {\n /**\n * The category of the logger. It is an array of strings.\n */\n readonly category: readonly string[];\n\n /**\n * The logger with the supercategory of the current logger. If the current\n * logger is the root logger, this is `null`.\n */\n readonly parent: Logger | null;\n\n /**\n * Get a child logger with the given subcategory.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const subLogger = logger.getChild(\"sub-category\");\n * ```\n *\n * The above code is equivalent to:\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const subLogger = getLogger([\"category\", \"sub-category\"]);\n * ```\n *\n * @param subcategory The subcategory.\n * @returns The child logger.\n */\n getChild(\n subcategory: string | readonly [string] | readonly [string, ...string[]],\n ): Logger;\n\n /**\n * Get a logger with contextual properties. This is useful for\n * log multiple messages with the shared set of properties.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const ctx = logger.with({ foo: 123, bar: \"abc\" });\n * ctx.info(\"A message with {foo} and {bar}.\");\n * ctx.warn(\"Another message with {foo}, {bar}, and {baz}.\", { baz: true });\n * ```\n *\n * The above code is equivalent to:\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * logger.info(\"A message with {foo} and {bar}.\", { foo: 123, bar: \"abc\" });\n * logger.warn(\n * \"Another message with {foo}, {bar}, and {baz}.\",\n * { foo: 123, bar: \"abc\", baz: true },\n * );\n * ```\n *\n * @param properties\n * @returns\n * @since 0.5.0\n */\n with(properties: Record<string, unknown>): Logger;\n\n /**\n * Log a trace message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.trace `A trace message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n * @since 0.12.0\n */\n trace(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a trace message with properties.\n *\n * ```typescript\n * logger.trace('A trace message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.trace(\n * 'A trace message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n * @since 0.12.0\n */\n trace(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a trace values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.trace({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.trace('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.trace('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.12.0\n */\n trace(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a trace message. Use this when the message values are expensive\n * to compute and should only be computed if the message is actually logged.\n *\n * ```typescript\n * logger.trace(l => l`A trace message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n * @since 0.12.0\n */\n trace(callback: LogCallback): void;\n\n /**\n * Log a debug message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.debug `A debug message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n debug(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a debug message with properties.\n *\n * ```typescript\n * logger.debug('A debug message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.debug(\n * 'A debug message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n debug(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a debug values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.debug({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.debug('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.debug('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n debug(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a debug message. Use this when the message values are expensive\n * to compute and should only be computed if the message is actually logged.\n *\n * ```typescript\n * logger.debug(l => l`A debug message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n debug(callback: LogCallback): void;\n\n /**\n * Log an informational message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.info `An info message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n info(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log an informational message with properties.\n *\n * ```typescript\n * logger.info('An info message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.info(\n * 'An info message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n info(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log an informational values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.info({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.info('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.info('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n info(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log an informational message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.info(l => l`An info message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n info(callback: LogCallback): void;\n\n /**\n * Log a warning message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.warn `A warning message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n warn(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a warning message with properties.\n *\n * ```typescript\n * logger.warn('A warning message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.warn(\n * 'A warning message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n warn(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a warning values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.warn({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.warn('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.warn('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n warn(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a warning message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.warn(l => l`A warning message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n warn(callback: LogCallback): void;\n\n /**\n * Log a warning message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.warning `A warning message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n * @since 0.12.0\n */\n warning(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a warning message with properties.\n *\n * ```typescript\n * logger.warning('A warning message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.warning(\n * 'A warning message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n * @since 0.12.0\n */\n warning(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a warning values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.warning({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.warning('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.warning('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.12.0\n */\n warning(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a warning message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.warning(l => l`A warning message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n * @since 0.12.0\n */\n warning(callback: LogCallback): void;\n\n /**\n * Log an error message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.error `An error message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n error(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log an error message with properties.\n *\n * ```typescript\n * logger.warn('An error message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.error(\n * 'An error message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n error(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log an error values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.error({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.error('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.error('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n error(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log an error message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.error(l => l`An error message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n error(callback: LogCallback): void;\n\n /**\n * Log a fatal error message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.fatal `A fatal error message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n fatal(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a fatal error message with properties.\n *\n * ```typescript\n * logger.warn('A fatal error message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.fatal(\n * 'A fatal error message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n fatal(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a fatal error values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.fatal({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.fatal('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.fatal('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n fatal(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a fatal error message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n fatal(callback: LogCallback): void;\n}\n\n/**\n * A logging callback function. It is used to defer the computation of a\n * message template until it is actually logged.\n * @param prefix The message template prefix.\n * @returns The rendered message array.\n */\nexport type LogCallback = (prefix: LogTemplatePrefix) => unknown[];\n\n/**\n * A logging template prefix function. It is used to log a message in\n * a {@link LogCallback} function.\n * @param message The message template strings array.\n * @param values The message template values.\n * @returns The rendered message array.\n */\nexport type LogTemplatePrefix = (\n message: TemplateStringsArray,\n ...values: unknown[]\n) => unknown[];\n\n/**\n * A function type for logging methods in the {@link Logger} interface.\n * @since 1.0.0\n */\nexport interface LogMethod {\n /**\n * Log a message with the given level using a template string.\n * @param message The message template strings array.\n * @param values The message template values.\n */\n (\n message: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void;\n\n /**\n * Log a message with the given level with properties.\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n (\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a message with the given level with no message.\n * @param properties The values to log. Note that this does not take\n * a callback.\n */\n (properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a message with the given level.\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n (callback: LogCallback): void;\n}\n\n/**\n * Get a logger with the given category.\n *\n * ```typescript\n * const logger = getLogger([\"my-app\"]);\n * ```\n *\n * @param category The category of the logger. It can be a string or an array\n * of strings. If it is a string, it is equivalent to an array\n * with a single element.\n * @returns The logger.\n */\nexport function getLogger(category: string | readonly string[] = []): Logger {\n return LoggerImpl.getLogger(category);\n}\n\n/**\n * The symbol for the global root logger.\n */\nconst globalRootLoggerSymbol = Symbol.for(\"logtape.rootLogger\");\n\n/**\n * The global root logger registry.\n */\ninterface GlobalRootLoggerRegistry {\n [globalRootLoggerSymbol]?: LoggerImpl;\n}\n\n/**\n * A logger implementation. Do not use this directly; use {@link getLogger}\n * instead. This class is exported for testing purposes.\n */\nexport class LoggerImpl implements Logger {\n readonly parent: LoggerImpl | null;\n readonly children: Record<string, LoggerImpl | WeakRef<LoggerImpl>>;\n readonly category: readonly string[];\n readonly sinks: Sink[];\n parentSinks: \"inherit\" | \"override\" = \"inherit\";\n readonly filters: Filter[];\n lowestLevel: LogLevel | null = \"trace\";\n contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;\n\n static getLogger(category: string | readonly string[] = []): LoggerImpl {\n let rootLogger: LoggerImpl | null = globalRootLoggerSymbol in globalThis\n ? ((globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] ??\n null)\n : null;\n if (rootLogger == null) {\n rootLogger = new LoggerImpl(null, []);\n (globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] =\n rootLogger;\n }\n if (typeof category === \"string\") return rootLogger.getChild(category);\n if (category.length === 0) return rootLogger;\n return rootLogger.getChild(category as readonly [string, ...string[]]);\n }\n\n private constructor(parent: LoggerImpl | null, category: readonly string[]) {\n this.parent = parent;\n this.children = {};\n this.category = category;\n this.sinks = [];\n this.filters = [];\n }\n\n getChild(\n subcategory:\n | string\n | readonly [string]\n | readonly [string, ...(readonly string[])],\n ): LoggerImpl {\n const name = typeof subcategory === \"string\" ? subcategory : subcategory[0];\n const childRef = this.children[name];\n let child: LoggerImpl | undefined = childRef instanceof LoggerImpl\n ? childRef\n : childRef?.deref();\n if (child == null) {\n child = new LoggerImpl(this, [...this.category, name]);\n this.children[name] = \"WeakRef\" in globalThis\n ? new WeakRef(child)\n : child;\n }\n if (typeof subcategory === \"string\" || subcategory.length === 1) {\n return child;\n }\n return child.getChild(\n subcategory.slice(1) as [string, ...(readonly string[])],\n );\n }\n\n /**\n * Reset the logger. This removes all sinks and filters from the logger.\n */\n reset(): void {\n while (this.sinks.length > 0) this.sinks.shift();\n this.parentSinks = \"inherit\";\n while (this.filters.length > 0) this.filters.shift();\n this.lowestLevel = \"trace\";\n }\n\n /**\n * Reset the logger and all its descendants. This removes all sinks and\n * filters from the logger and all its descendants.\n */\n resetDescendants(): void {\n for (const child of Object.values(this.children)) {\n const logger = child instanceof LoggerImpl ? child : child.deref();\n if (logger != null) logger.resetDescendants();\n }\n this.reset();\n }\n\n with(properties: Record<string, unknown>): Logger {\n return new LoggerCtx(this, { ...properties });\n }\n\n filter(record: LogRecord): boolean {\n for (const filter of this.filters) {\n if (!filter(record)) return false;\n }\n if (this.filters.length < 1) return this.parent?.filter(record) ?? true;\n return true;\n }\n\n *getSinks(level: LogLevel): Iterable<Sink> {\n if (\n this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0\n ) {\n return;\n }\n if (this.parent != null && this.parentSinks === \"inherit\") {\n for (const sink of this.parent.getSinks(level)) yield sink;\n }\n for (const sink of this.sinks) yield sink;\n }\n\n emit(record: LogRecord, bypassSinks?: Set<Sink>): void {\n if (\n this.lowestLevel === null ||\n compareLogLevel(record.level, this.lowestLevel) < 0 ||\n !this.filter(record)\n ) {\n return;\n }\n for (const sink of this.getSinks(record.level)) {\n if (bypassSinks?.has(sink)) continue;\n try {\n sink(record);\n } catch (error) {\n const bypassSinks2 = new Set(bypassSinks);\n bypassSinks2.add(sink);\n metaLogger.log(\n \"fatal\",\n \"Failed to emit a log record to sink {sink}: {error}\",\n { sink, error, record },\n bypassSinks2,\n );\n }\n }\n }\n\n log(\n level: LogLevel,\n rawMessage: string,\n properties: Record<string, unknown> | (() => Record<string, unknown>),\n bypassSinks?: Set<Sink>,\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n let cachedProps: Record<string, unknown> | undefined = undefined;\n const record: LogRecord = typeof properties === \"function\"\n ? {\n category: this.category,\n level,\n timestamp: Date.now(),\n get message() {\n return parseMessageTemplate(rawMessage, this.properties);\n },\n rawMessage,\n get properties() {\n if (cachedProps == null) {\n cachedProps = {\n ...implicitContext,\n ...properties(),\n };\n }\n return cachedProps;\n },\n }\n : {\n category: this.category,\n level,\n timestamp: Date.now(),\n message: parseMessageTemplate(rawMessage, {\n ...implicitContext,\n ...properties,\n }),\n rawMessage,\n properties: { ...implicitContext, ...properties },\n };\n this.emit(record, bypassSinks);\n }\n\n logLazily(\n level: LogLevel,\n callback: LogCallback,\n properties: Record<string, unknown> = {},\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n let rawMessage: TemplateStringsArray | undefined = undefined;\n let msg: unknown[] | undefined = undefined;\n function realizeMessage(): [unknown[], TemplateStringsArray] {\n if (msg == null || rawMessage == null) {\n msg = callback((tpl, ...values) => {\n rawMessage = tpl;\n return renderMessage(tpl, values);\n });\n if (rawMessage == null) throw new TypeError(\"No log record was made.\");\n }\n return [msg, rawMessage];\n }\n this.emit({\n category: this.category,\n level,\n get message() {\n return realizeMessage()[0];\n },\n get rawMessage() {\n return realizeMessage()[1];\n },\n timestamp: Date.now(),\n properties: { ...implicitContext, ...properties },\n });\n }\n\n logTemplate(\n level: LogLevel,\n messageTemplate: TemplateStringsArray,\n values: unknown[],\n properties: Record<string, unknown> = {},\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n this.emit({\n category: this.category,\n level,\n message: renderMessage(messageTemplate, values),\n rawMessage: messageTemplate,\n timestamp: Date.now(),\n properties: { ...implicitContext, ...properties },\n });\n }\n\n trace(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"trace\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"trace\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"trace\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"trace\", message as TemplateStringsArray, values);\n }\n }\n\n debug(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"debug\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"debug\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"debug\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"debug\", message as TemplateStringsArray, values);\n }\n }\n\n info(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"info\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"info\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"info\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"info\", message as TemplateStringsArray, values);\n }\n }\n\n warn(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\n \"warning\",\n message,\n (values[0] ?? {}) as Record<string, unknown>,\n );\n } else if (typeof message === \"function\") {\n this.logLazily(\"warning\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"warning\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"warning\", message as TemplateStringsArray, values);\n }\n }\n\n warning(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n this.warn(message, ...values);\n }\n\n error(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"error\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"error\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"error\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"error\", message as TemplateStringsArray, values);\n }\n }\n\n fatal(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"fatal\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"fatal\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"fatal\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"fatal\", message as TemplateStringsArray, values);\n }\n }\n}\n\n/**\n * A logger implementation with contextual properties. Do not use this\n * directly; use {@link Logger.with} instead. This class is exported\n * for testing purposes.\n */\nexport class LoggerCtx implements Logger {\n logger: LoggerImpl;\n properties: Record<string, unknown>;\n\n constructor(logger: LoggerImpl, properties: Record<string, unknown>) {\n this.logger = logger;\n this.properties = properties;\n }\n\n get category(): readonly string[] {\n return this.logger.category;\n }\n\n get parent(): Logger | null {\n return this.logger.parent;\n }\n\n getChild(\n subcategory: string | readonly [string] | readonly [string, ...string[]],\n ): Logger {\n return this.logger.getChild(subcategory).with(this.properties);\n }\n\n with(properties: Record<string, unknown>): Logger {\n return new LoggerCtx(this.logger, { ...this.properties, ...properties });\n }\n\n log(\n level: LogLevel,\n message: string,\n properties: Record<string, unknown> | (() => Record<string, unknown>),\n bypassSinks?: Set<Sink>,\n ): void {\n this.logger.log(\n level,\n message,\n typeof properties === \"function\"\n ? () => ({\n ...this.properties,\n ...properties(),\n })\n : { ...this.properties, ...properties },\n bypassSinks,\n );\n }\n\n logLazily(level: LogLevel, callback: LogCallback): void {\n this.logger.logLazily(level, callback, this.properties);\n }\n\n logTemplate(\n level: LogLevel,\n messageTemplate: TemplateStringsArray,\n values: unknown[],\n ): void {\n this.logger.logTemplate(level, messageTemplate, values, this.properties);\n }\n\n trace(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"trace\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"trace\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"trace\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"trace\", message as TemplateStringsArray, values);\n }\n }\n\n debug(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"debug\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"debug\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"debug\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"debug\", message as TemplateStringsArray, values);\n }\n }\n\n info(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"info\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"info\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"info\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"info\", message as TemplateStringsArray, values);\n }\n }\n\n warn(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\n \"warning\",\n message,\n (values[0] ?? {}) as Record<string, unknown>,\n );\n } else if (typeof message === \"function\") {\n this.logLazily(\"warning\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"warning\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"warning\", message as TemplateStringsArray, values);\n }\n }\n\n warning(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n this.warn(message, ...values);\n }\n\n error(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"error\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"error\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"error\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"error\", message as TemplateStringsArray, values);\n }\n }\n\n fatal(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"fatal\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"fatal\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"fatal\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"fatal\", message as TemplateStringsArray, values);\n }\n }\n}\n\n/**\n * The meta logger. It is a logger with the category `[\"logtape\", \"meta\"]`.\n */\nconst metaLogger = LoggerImpl.getLogger([\"logtape\", \"meta\"]);\n\n/**\n * Parse a message template into a message template array and a values array.\n * @param template The message template.\n * @param properties The values to replace placeholders with.\n * @returns The message template array and the values array.\n */\nexport function parseMessageTemplate(\n template: string,\n properties: Record<string, unknown>,\n): readonly unknown[] {\n const length = template.length;\n if (length === 0) return [\"\"];\n\n // Fast path: no placeholders\n if (!template.includes(\"{\")) return [template];\n\n const message: unknown[] = [];\n let startIndex = 0;\n\n for (let i = 0; i < length; i++) {\n const char = template[i];\n\n if (char === \"{\") {\n const nextChar = i + 1 < length ? template[i + 1] : \"\";\n\n if (nextChar === \"{\") {\n // Escaped { character - skip and continue\n i++; // Skip the next {\n continue;\n }\n\n // Find the closing }\n const closeIndex = template.indexOf(\"}\", i + 1);\n if (closeIndex === -1) {\n // No closing } found, treat as literal text\n continue;\n }\n\n // Add text before placeholder\n const beforeText = template.slice(startIndex, i);\n message.push(beforeText.replace(/{{/g, \"{\").replace(/}}/g, \"}\"));\n\n // Extract and process placeholder key\n const key = template.slice(i + 1, closeIndex);\n\n // Resolve property value\n let prop: unknown;\n\n // Check for wildcard patterns\n const trimmedKey = key.trim();\n if (trimmedKey === \"*\") {\n // This is a wildcard pattern\n prop = key in properties\n ? properties[key]\n : \"*\" in properties\n ? properties[\"*\"]\n : properties;\n } else {\n // Regular property lookup with possible whitespace handling\n if (key !== trimmedKey) {\n // Key has leading/trailing whitespace\n prop = key in properties ? properties[key] : properties[trimmedKey];\n } else {\n // Key has no leading/trailing whitespace\n prop = properties[key];\n }\n }\n\n message.push(prop);\n i = closeIndex; // Move to the }\n startIndex = i + 1;\n } else if (char === \"}\" && i + 1 < length && template[i + 1] === \"}\") {\n // Escaped } character - skip\n i++; // Skip the next }\n }\n }\n\n // Add remaining text\n const remainingText = template.slice(startIndex);\n message.push(remainingText.replace(/{{/g, \"{\").replace(/}}/g, \"}\"));\n\n return message;\n}\n\n/**\n * Render a message template with values.\n * @param template The message template.\n * @param values The message template values.\n * @returns The message template values interleaved between the substitution\n * values.\n */\nexport function renderMessage(\n template: TemplateStringsArray,\n values: readonly unknown[],\n): unknown[] {\n const args = [];\n for (let i = 0; i < template.length; i++) {\n args.push(template[i]);\n if (i < values.length) args.push(values[i]);\n }\n return args;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6vBA,SAAgB,UAAUA,WAAuC,CAAE,GAAU;AAC3E,QAAO,WAAW,UAAU,SAAS;AACtC;;;;AAKD,MAAM,yBAAyB,OAAO,IAAI,qBAAqB;;;;;AAa/D,IAAa,aAAb,MAAa,WAA6B;CACxC,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,cAAsC;CACtC,AAAS;CACT,cAA+B;CAC/B;CAEA,OAAO,UAAUA,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I,CAAC;AAEnE,QAAO;AACR;;;;;;;;AASD,SAAgB,cACdC,UACAC,QACW;CACX,MAAM,OAAO,CAAE;AACf,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,OAAK,KAAK,SAAS,GAAG;AACtB,MAAI,IAAI,OAAO,OAAQ,MAAK,KAAK,OAAO,GAAG;CAC5C;AACD,QAAO;AACR"}
1
+ {"version":3,"file":"logger.js","names":["category: string | readonly string[]","rootLogger: LoggerImpl | null","parent: LoggerImpl | null","category: readonly string[]","subcategory:\n | string\n | readonly [string]\n | readonly [string, ...(readonly string[])]","child: LoggerImpl | undefined","properties: Record<string, unknown>","record: LogRecord","level: LogLevel","record: Omit<LogRecord, \"category\"> | LogRecord","bypassSinks?: Set<Sink>","fullRecord: LogRecord","rawMessage: string","properties: Record<string, unknown> | (() => Record<string, unknown>)","cachedProps: Record<string, unknown> | undefined","callback: LogCallback","rawMessage: TemplateStringsArray | undefined","msg: unknown[] | undefined","messageTemplate: TemplateStringsArray","values: unknown[]","message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>","logger: LoggerImpl","subcategory: string | readonly [string] | readonly [string, ...string[]]","message: string","record: Omit<LogRecord, \"category\">","template: string","message: unknown[]","prop: unknown","template: TemplateStringsArray","values: readonly unknown[]"],"sources":["../src/logger.ts"],"sourcesContent":["import type { ContextLocalStorage } from \"./context.ts\";\nimport type { Filter } from \"./filter.ts\";\nimport { compareLogLevel, type LogLevel } from \"./level.ts\";\nimport type { LogRecord } from \"./record.ts\";\nimport type { Sink } from \"./sink.ts\";\n\n/**\n * A logger interface. It provides methods to log messages at different\n * severity levels.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * logger.trace `A trace message with ${value}`\n * logger.debug `A debug message with ${value}.`;\n * logger.info `An info message with ${value}.`;\n * logger.warn `A warning message with ${value}.`;\n * logger.error `An error message with ${value}.`;\n * logger.fatal `A fatal error message with ${value}.`;\n * ```\n */\nexport interface Logger {\n /**\n * The category of the logger. It is an array of strings.\n */\n readonly category: readonly string[];\n\n /**\n * The logger with the supercategory of the current logger. If the current\n * logger is the root logger, this is `null`.\n */\n readonly parent: Logger | null;\n\n /**\n * Get a child logger with the given subcategory.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const subLogger = logger.getChild(\"sub-category\");\n * ```\n *\n * The above code is equivalent to:\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const subLogger = getLogger([\"category\", \"sub-category\"]);\n * ```\n *\n * @param subcategory The subcategory.\n * @returns The child logger.\n */\n getChild(\n subcategory: string | readonly [string] | readonly [string, ...string[]],\n ): Logger;\n\n /**\n * Get a logger with contextual properties. This is useful for\n * log multiple messages with the shared set of properties.\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * const ctx = logger.with({ foo: 123, bar: \"abc\" });\n * ctx.info(\"A message with {foo} and {bar}.\");\n * ctx.warn(\"Another message with {foo}, {bar}, and {baz}.\", { baz: true });\n * ```\n *\n * The above code is equivalent to:\n *\n * ```typescript\n * const logger = getLogger(\"category\");\n * logger.info(\"A message with {foo} and {bar}.\", { foo: 123, bar: \"abc\" });\n * logger.warn(\n * \"Another message with {foo}, {bar}, and {baz}.\",\n * { foo: 123, bar: \"abc\", baz: true },\n * );\n * ```\n *\n * @param properties\n * @returns\n * @since 0.5.0\n */\n with(properties: Record<string, unknown>): Logger;\n\n /**\n * Log a trace message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.trace `A trace message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n * @since 0.12.0\n */\n trace(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a trace message with properties.\n *\n * ```typescript\n * logger.trace('A trace message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.trace(\n * 'A trace message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n * @since 0.12.0\n */\n trace(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a trace values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.trace({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.trace('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.trace('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.12.0\n */\n trace(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a trace message. Use this when the message values are expensive\n * to compute and should only be computed if the message is actually logged.\n *\n * ```typescript\n * logger.trace(l => l`A trace message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n * @since 0.12.0\n */\n trace(callback: LogCallback): void;\n\n /**\n * Log a debug message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.debug `A debug message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n debug(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a debug message with properties.\n *\n * ```typescript\n * logger.debug('A debug message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.debug(\n * 'A debug message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n debug(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a debug values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.debug({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.debug('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.debug('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n debug(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a debug message. Use this when the message values are expensive\n * to compute and should only be computed if the message is actually logged.\n *\n * ```typescript\n * logger.debug(l => l`A debug message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n debug(callback: LogCallback): void;\n\n /**\n * Log an informational message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.info `An info message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n info(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log an informational message with properties.\n *\n * ```typescript\n * logger.info('An info message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.info(\n * 'An info message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n info(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log an informational values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.info({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.info('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.info('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n info(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log an informational message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.info(l => l`An info message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n info(callback: LogCallback): void;\n\n /**\n * Log a warning message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.warn `A warning message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n warn(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a warning message with properties.\n *\n * ```typescript\n * logger.warn('A warning message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.warn(\n * 'A warning message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n warn(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a warning values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.warn({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.warn('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.warn('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n warn(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a warning message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.warn(l => l`A warning message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n warn(callback: LogCallback): void;\n\n /**\n * Log a warning message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.warning `A warning message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n * @since 0.12.0\n */\n warning(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a warning message with properties.\n *\n * ```typescript\n * logger.warning('A warning message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.warning(\n * 'A warning message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n * @since 0.12.0\n */\n warning(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a warning values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.warning({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.warning('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.warning('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.12.0\n */\n warning(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a warning message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.warning(l => l`A warning message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n * @since 0.12.0\n */\n warning(callback: LogCallback): void;\n\n /**\n * Log an error message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.error `An error message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n error(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log an error message with properties.\n *\n * ```typescript\n * logger.warn('An error message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.error(\n * 'An error message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n error(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log an error values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.error({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.error('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.error('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n error(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log an error message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.error(l => l`An error message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n error(callback: LogCallback): void;\n\n /**\n * Log a fatal error message. Use this as a template string prefix.\n *\n * ```typescript\n * logger.fatal `A fatal error message with ${value}.`;\n * ```\n *\n * @param message The message template strings array.\n * @param values The message template values.\n */\n fatal(message: TemplateStringsArray, ...values: readonly unknown[]): void;\n\n /**\n * Log a fatal error message with properties.\n *\n * ```typescript\n * logger.warn('A fatal error message with {value}.', { value });\n * ```\n *\n * If the properties are expensive to compute, you can pass a callback that\n * returns the properties:\n *\n * ```typescript\n * logger.fatal(\n * 'A fatal error message with {value}.',\n * () => ({ value: expensiveComputation() })\n * );\n * ```\n *\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n fatal(\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a fatal error values with no message. This is useful when you\n * want to log properties without a message, e.g., when you want to log\n * the context of a request or an operation.\n *\n * ```typescript\n * logger.fatal({ method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * Note that this is a shorthand for:\n *\n * ```typescript\n * logger.fatal('{*}', { method: 'GET', url: '/api/v1/resource' });\n * ```\n *\n * If the properties are expensive to compute, you cannot use this shorthand\n * and should use the following syntax instead:\n *\n * ```typescript\n * logger.fatal('{*}', () => ({\n * method: expensiveMethod(),\n * url: expensiveUrl(),\n * }));\n * ```\n *\n * @param properties The values to log. Note that this does not take\n * a callback.\n * @since 0.11.0\n */\n fatal(properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a fatal error message. Use this when the message values are\n * expensive to compute and should only be computed if the message is actually\n * logged.\n *\n * ```typescript\n * logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);\n * ```\n *\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n fatal(callback: LogCallback): void;\n\n /**\n * Emits a log record with custom fields while using this logger's\n * category.\n *\n * This is a low-level API for integration scenarios where you need full\n * control over the log record, particularly for preserving timestamps\n * from external systems.\n *\n * ```typescript\n * const logger = getLogger([\"my-app\", \"integration\"]);\n *\n * // Emit a log with a custom timestamp\n * logger.emit({\n * timestamp: kafkaLog.originalTimestamp,\n * level: \"info\",\n * message: [kafkaLog.message],\n * rawMessage: kafkaLog.message,\n * properties: {\n * source: \"kafka\",\n * partition: kafkaLog.partition,\n * offset: kafkaLog.offset,\n * },\n * });\n * ```\n *\n * @param record Log record without category field (category comes from\n * the logger instance)\n * @since 1.1.0\n */\n emit(record: Omit<LogRecord, \"category\">): void;\n}\n\n/**\n * A logging callback function. It is used to defer the computation of a\n * message template until it is actually logged.\n * @param prefix The message template prefix.\n * @returns The rendered message array.\n */\nexport type LogCallback = (prefix: LogTemplatePrefix) => unknown[];\n\n/**\n * A logging template prefix function. It is used to log a message in\n * a {@link LogCallback} function.\n * @param message The message template strings array.\n * @param values The message template values.\n * @returns The rendered message array.\n */\nexport type LogTemplatePrefix = (\n message: TemplateStringsArray,\n ...values: unknown[]\n) => unknown[];\n\n/**\n * A function type for logging methods in the {@link Logger} interface.\n * @since 1.0.0\n */\nexport interface LogMethod {\n /**\n * Log a message with the given level using a template string.\n * @param message The message template strings array.\n * @param values The message template values.\n */\n (\n message: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void;\n\n /**\n * Log a message with the given level with properties.\n * @param message The message template. Placeholders to be replaced with\n * `values` are indicated by keys in curly braces (e.g.,\n * `{value}`).\n * @param properties The values to replace placeholders with. For lazy\n * evaluation, this can be a callback that returns the\n * properties.\n */\n (\n message: string,\n properties?: Record<string, unknown> | (() => Record<string, unknown>),\n ): void;\n\n /**\n * Log a message with the given level with no message.\n * @param properties The values to log. Note that this does not take\n * a callback.\n */\n (properties: Record<string, unknown>): void;\n\n /**\n * Lazily log a message with the given level.\n * @param callback A callback that returns the message template prefix.\n * @throws {TypeError} If no log record was made inside the callback.\n */\n (callback: LogCallback): void;\n}\n\n/**\n * Get a logger with the given category.\n *\n * ```typescript\n * const logger = getLogger([\"my-app\"]);\n * ```\n *\n * @param category The category of the logger. It can be a string or an array\n * of strings. If it is a string, it is equivalent to an array\n * with a single element.\n * @returns The logger.\n */\nexport function getLogger(category: string | readonly string[] = []): Logger {\n return LoggerImpl.getLogger(category);\n}\n\n/**\n * The symbol for the global root logger.\n */\nconst globalRootLoggerSymbol = Symbol.for(\"logtape.rootLogger\");\n\n/**\n * The global root logger registry.\n */\ninterface GlobalRootLoggerRegistry {\n [globalRootLoggerSymbol]?: LoggerImpl;\n}\n\n/**\n * A logger implementation. Do not use this directly; use {@link getLogger}\n * instead. This class is exported for testing purposes.\n */\nexport class LoggerImpl implements Logger {\n readonly parent: LoggerImpl | null;\n readonly children: Record<string, LoggerImpl | WeakRef<LoggerImpl>>;\n readonly category: readonly string[];\n readonly sinks: Sink[];\n parentSinks: \"inherit\" | \"override\" = \"inherit\";\n readonly filters: Filter[];\n lowestLevel: LogLevel | null = \"trace\";\n contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;\n\n static getLogger(category: string | readonly string[] = []): LoggerImpl {\n let rootLogger: LoggerImpl | null = globalRootLoggerSymbol in globalThis\n ? ((globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] ??\n null)\n : null;\n if (rootLogger == null) {\n rootLogger = new LoggerImpl(null, []);\n (globalThis as GlobalRootLoggerRegistry)[globalRootLoggerSymbol] =\n rootLogger;\n }\n if (typeof category === \"string\") return rootLogger.getChild(category);\n if (category.length === 0) return rootLogger;\n return rootLogger.getChild(category as readonly [string, ...string[]]);\n }\n\n private constructor(parent: LoggerImpl | null, category: readonly string[]) {\n this.parent = parent;\n this.children = {};\n this.category = category;\n this.sinks = [];\n this.filters = [];\n }\n\n getChild(\n subcategory:\n | string\n | readonly [string]\n | readonly [string, ...(readonly string[])],\n ): LoggerImpl {\n const name = typeof subcategory === \"string\" ? subcategory : subcategory[0];\n const childRef = this.children[name];\n let child: LoggerImpl | undefined = childRef instanceof LoggerImpl\n ? childRef\n : childRef?.deref();\n if (child == null) {\n child = new LoggerImpl(this, [...this.category, name]);\n this.children[name] = \"WeakRef\" in globalThis\n ? new WeakRef(child)\n : child;\n }\n if (typeof subcategory === \"string\" || subcategory.length === 1) {\n return child;\n }\n return child.getChild(\n subcategory.slice(1) as [string, ...(readonly string[])],\n );\n }\n\n /**\n * Reset the logger. This removes all sinks and filters from the logger.\n */\n reset(): void {\n while (this.sinks.length > 0) this.sinks.shift();\n this.parentSinks = \"inherit\";\n while (this.filters.length > 0) this.filters.shift();\n this.lowestLevel = \"trace\";\n }\n\n /**\n * Reset the logger and all its descendants. This removes all sinks and\n * filters from the logger and all its descendants.\n */\n resetDescendants(): void {\n for (const child of Object.values(this.children)) {\n const logger = child instanceof LoggerImpl ? child : child.deref();\n if (logger != null) logger.resetDescendants();\n }\n this.reset();\n }\n\n with(properties: Record<string, unknown>): Logger {\n return new LoggerCtx(this, { ...properties });\n }\n\n filter(record: LogRecord): boolean {\n for (const filter of this.filters) {\n if (!filter(record)) return false;\n }\n if (this.filters.length < 1) return this.parent?.filter(record) ?? true;\n return true;\n }\n\n *getSinks(level: LogLevel): Iterable<Sink> {\n if (\n this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0\n ) {\n return;\n }\n if (this.parent != null && this.parentSinks === \"inherit\") {\n for (const sink of this.parent.getSinks(level)) yield sink;\n }\n for (const sink of this.sinks) yield sink;\n }\n\n emit(record: Omit<LogRecord, \"category\">): void;\n emit(record: LogRecord, bypassSinks?: Set<Sink>): void;\n emit(\n record: Omit<LogRecord, \"category\"> | LogRecord,\n bypassSinks?: Set<Sink>,\n ): void {\n const fullRecord: LogRecord = \"category\" in record\n ? record as LogRecord\n : { ...record, category: this.category };\n\n if (\n this.lowestLevel === null ||\n compareLogLevel(fullRecord.level, this.lowestLevel) < 0 ||\n !this.filter(fullRecord)\n ) {\n return;\n }\n for (const sink of this.getSinks(fullRecord.level)) {\n if (bypassSinks?.has(sink)) continue;\n try {\n sink(fullRecord);\n } catch (error) {\n const bypassSinks2 = new Set(bypassSinks);\n bypassSinks2.add(sink);\n metaLogger.log(\n \"fatal\",\n \"Failed to emit a log record to sink {sink}: {error}\",\n { sink, error, record: fullRecord },\n bypassSinks2,\n );\n }\n }\n }\n\n log(\n level: LogLevel,\n rawMessage: string,\n properties: Record<string, unknown> | (() => Record<string, unknown>),\n bypassSinks?: Set<Sink>,\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n let cachedProps: Record<string, unknown> | undefined = undefined;\n const record: LogRecord = typeof properties === \"function\"\n ? {\n category: this.category,\n level,\n timestamp: Date.now(),\n get message() {\n return parseMessageTemplate(rawMessage, this.properties);\n },\n rawMessage,\n get properties() {\n if (cachedProps == null) {\n cachedProps = {\n ...implicitContext,\n ...properties(),\n };\n }\n return cachedProps;\n },\n }\n : {\n category: this.category,\n level,\n timestamp: Date.now(),\n message: parseMessageTemplate(rawMessage, {\n ...implicitContext,\n ...properties,\n }),\n rawMessage,\n properties: { ...implicitContext, ...properties },\n };\n this.emit(record, bypassSinks);\n }\n\n logLazily(\n level: LogLevel,\n callback: LogCallback,\n properties: Record<string, unknown> = {},\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n let rawMessage: TemplateStringsArray | undefined = undefined;\n let msg: unknown[] | undefined = undefined;\n function realizeMessage(): [unknown[], TemplateStringsArray] {\n if (msg == null || rawMessage == null) {\n msg = callback((tpl, ...values) => {\n rawMessage = tpl;\n return renderMessage(tpl, values);\n });\n if (rawMessage == null) throw new TypeError(\"No log record was made.\");\n }\n return [msg, rawMessage];\n }\n this.emit({\n category: this.category,\n level,\n get message() {\n return realizeMessage()[0];\n },\n get rawMessage() {\n return realizeMessage()[1];\n },\n timestamp: Date.now(),\n properties: { ...implicitContext, ...properties },\n });\n }\n\n logTemplate(\n level: LogLevel,\n messageTemplate: TemplateStringsArray,\n values: unknown[],\n properties: Record<string, unknown> = {},\n ): void {\n const implicitContext =\n LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};\n this.emit({\n category: this.category,\n level,\n message: renderMessage(messageTemplate, values),\n rawMessage: messageTemplate,\n timestamp: Date.now(),\n properties: { ...implicitContext, ...properties },\n });\n }\n\n trace(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"trace\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"trace\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"trace\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"trace\", message as TemplateStringsArray, values);\n }\n }\n\n debug(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"debug\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"debug\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"debug\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"debug\", message as TemplateStringsArray, values);\n }\n }\n\n info(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"info\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"info\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"info\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"info\", message as TemplateStringsArray, values);\n }\n }\n\n warn(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\n \"warning\",\n message,\n (values[0] ?? {}) as Record<string, unknown>,\n );\n } else if (typeof message === \"function\") {\n this.logLazily(\"warning\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"warning\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"warning\", message as TemplateStringsArray, values);\n }\n }\n\n warning(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n this.warn(message, ...values);\n }\n\n error(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"error\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"error\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"error\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"error\", message as TemplateStringsArray, values);\n }\n }\n\n fatal(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"fatal\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"fatal\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"fatal\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"fatal\", message as TemplateStringsArray, values);\n }\n }\n}\n\n/**\n * A logger implementation with contextual properties. Do not use this\n * directly; use {@link Logger.with} instead. This class is exported\n * for testing purposes.\n */\nexport class LoggerCtx implements Logger {\n logger: LoggerImpl;\n properties: Record<string, unknown>;\n\n constructor(logger: LoggerImpl, properties: Record<string, unknown>) {\n this.logger = logger;\n this.properties = properties;\n }\n\n get category(): readonly string[] {\n return this.logger.category;\n }\n\n get parent(): Logger | null {\n return this.logger.parent;\n }\n\n getChild(\n subcategory: string | readonly [string] | readonly [string, ...string[]],\n ): Logger {\n return this.logger.getChild(subcategory).with(this.properties);\n }\n\n with(properties: Record<string, unknown>): Logger {\n return new LoggerCtx(this.logger, { ...this.properties, ...properties });\n }\n\n log(\n level: LogLevel,\n message: string,\n properties: Record<string, unknown> | (() => Record<string, unknown>),\n bypassSinks?: Set<Sink>,\n ): void {\n this.logger.log(\n level,\n message,\n typeof properties === \"function\"\n ? () => ({\n ...this.properties,\n ...properties(),\n })\n : { ...this.properties, ...properties },\n bypassSinks,\n );\n }\n\n logLazily(level: LogLevel, callback: LogCallback): void {\n this.logger.logLazily(level, callback, this.properties);\n }\n\n logTemplate(\n level: LogLevel,\n messageTemplate: TemplateStringsArray,\n values: unknown[],\n ): void {\n this.logger.logTemplate(level, messageTemplate, values, this.properties);\n }\n\n emit(record: Omit<LogRecord, \"category\">): void {\n const recordWithContext = {\n ...record,\n properties: { ...this.properties, ...record.properties },\n };\n this.logger.emit(recordWithContext);\n }\n\n trace(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"trace\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"trace\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"trace\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"trace\", message as TemplateStringsArray, values);\n }\n }\n\n debug(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"debug\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"debug\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"debug\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"debug\", message as TemplateStringsArray, values);\n }\n }\n\n info(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"info\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"info\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"info\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"info\", message as TemplateStringsArray, values);\n }\n }\n\n warn(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\n \"warning\",\n message,\n (values[0] ?? {}) as Record<string, unknown>,\n );\n } else if (typeof message === \"function\") {\n this.logLazily(\"warning\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"warning\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"warning\", message as TemplateStringsArray, values);\n }\n }\n\n warning(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n this.warn(message, ...values);\n }\n\n error(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"error\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"error\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"error\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"error\", message as TemplateStringsArray, values);\n }\n }\n\n fatal(\n message:\n | TemplateStringsArray\n | string\n | LogCallback\n | Record<string, unknown>,\n ...values: unknown[]\n ): void {\n if (typeof message === \"string\") {\n this.log(\"fatal\", message, (values[0] ?? {}) as Record<string, unknown>);\n } else if (typeof message === \"function\") {\n this.logLazily(\"fatal\", message);\n } else if (!Array.isArray(message)) {\n this.log(\"fatal\", \"{*}\", message as Record<string, unknown>);\n } else {\n this.logTemplate(\"fatal\", message as TemplateStringsArray, values);\n }\n }\n}\n\n/**\n * The meta logger. It is a logger with the category `[\"logtape\", \"meta\"]`.\n */\nconst metaLogger = LoggerImpl.getLogger([\"logtape\", \"meta\"]);\n\n/**\n * Parse a message template into a message template array and a values array.\n * @param template The message template.\n * @param properties The values to replace placeholders with.\n * @returns The message template array and the values array.\n */\nexport function parseMessageTemplate(\n template: string,\n properties: Record<string, unknown>,\n): readonly unknown[] {\n const length = template.length;\n if (length === 0) return [\"\"];\n\n // Fast path: no placeholders\n if (!template.includes(\"{\")) return [template];\n\n const message: unknown[] = [];\n let startIndex = 0;\n\n for (let i = 0; i < length; i++) {\n const char = template[i];\n\n if (char === \"{\") {\n const nextChar = i + 1 < length ? template[i + 1] : \"\";\n\n if (nextChar === \"{\") {\n // Escaped { character - skip and continue\n i++; // Skip the next {\n continue;\n }\n\n // Find the closing }\n const closeIndex = template.indexOf(\"}\", i + 1);\n if (closeIndex === -1) {\n // No closing } found, treat as literal text\n continue;\n }\n\n // Add text before placeholder\n const beforeText = template.slice(startIndex, i);\n message.push(beforeText.replace(/{{/g, \"{\").replace(/}}/g, \"}\"));\n\n // Extract and process placeholder key\n const key = template.slice(i + 1, closeIndex);\n\n // Resolve property value\n let prop: unknown;\n\n // Check for wildcard patterns\n const trimmedKey = key.trim();\n if (trimmedKey === \"*\") {\n // This is a wildcard pattern\n prop = key in properties\n ? properties[key]\n : \"*\" in properties\n ? properties[\"*\"]\n : properties;\n } else {\n // Regular property lookup with possible whitespace handling\n if (key !== trimmedKey) {\n // Key has leading/trailing whitespace\n prop = key in properties ? properties[key] : properties[trimmedKey];\n } else {\n // Key has no leading/trailing whitespace\n prop = properties[key];\n }\n }\n\n message.push(prop);\n i = closeIndex; // Move to the }\n startIndex = i + 1;\n } else if (char === \"}\" && i + 1 < length && template[i + 1] === \"}\") {\n // Escaped } character - skip\n i++; // Skip the next }\n }\n }\n\n // Add remaining text\n const remainingText = template.slice(startIndex);\n message.push(remainingText.replace(/{{/g, \"{\").replace(/}}/g, \"}\"));\n\n return message;\n}\n\n/**\n * Render a message template with values.\n * @param template The message template.\n * @param values The message template values.\n * @returns The message template values interleaved between the substitution\n * values.\n */\nexport function renderMessage(\n template: TemplateStringsArray,\n values: readonly unknown[],\n): unknown[] {\n const args = [];\n for (let i = 0; i < template.length; i++) {\n args.push(template[i]);\n if (i < values.length) args.push(values[i]);\n }\n return args;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4xBA,SAAgB,UAAUA,WAAuC,CAAE,GAAU;AAC3E,QAAO,WAAW,UAAU,SAAS;AACtC;;;;AAKD,MAAM,yBAAyB,OAAO,IAAI,qBAAqB;;;;;AAa/D,IAAa,aAAb,MAAa,WAA6B;CACxC,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,cAAsC;CACtC,AAAS;CACT,cAA+B;CAC/B;CAEA,OAAO,UAAUA,WAAuC,CAAE,GAAc;EACtE,IAAIC,aAAgC,0BAA0B,aACxD,WAAwC,2BAC1C,OACA;AACJ,MAAI,cAAc,MAAM;AACtB,gBAAa,IAAI,WAAW,MAAM,CAAE;AACpC,GAAC,WAAwC,0BACvC;EACH;AACD,aAAW,aAAa,SAAU,QAAO,WAAW,SAAS,SAAS;AACtE,MAAI,SAAS,WAAW,EAAG,QAAO;AAClC,SAAO,WAAW,SAAS,SAA2C;CACvE;CAED,AAAQ,YAAYC,QAA2BC,UAA6B;AAC1E,OAAK,SAAS;AACd,OAAK,WAAW,CAAE;AAClB,OAAK,WAAW;AAChB,OAAK,QAAQ,CAAE;AACf,OAAK,UAAU,CAAE;CAClB;CAED,SACEC,aAIY;EACZ,MAAM,cAAc,gBAAgB,WAAW,cAAc,YAAY;EACzE,MAAM,WAAW,KAAK,SAAS;EAC/B,IAAIC,QAAgC,oBAAoB,aACpD,WACA,UAAU,OAAO;AACrB,MAAI,SAAS,MAAM;AACjB,WAAQ,IAA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AQ,KAAK;EAC/B,MAAM,OAAO,SAAS;AAEtB,MAAI,SAAS,KAAK;GAChB,MAAM,WAAW,IAAI,IAAI,SAAS,SAAS,IAAI,KAAK;AAEpD,OAAI,aAAa,KAAK;AAEpB;AACA;GACD;GAGD,MAAM,aAAa,SAAS,QAAQ,KAAK,IAAI,EAAE;AAC/C,OAAI,eAAe,GAEjB;GAIF,MAAM,aAAa,SAAS,MAAM,YAAY,EAAE;AAChD,WAAQ,KAAK,WAAW,QAAQ,OAAO,IAAI,CAAC,QAAQ,OAAO,IAAI,CAAC;GAGhE,MAAM,MAAM,SAAS,MAAM,IAAI,GAAG,WAAW;GAG7C,IAAIC;GAGJ,MAAM,aAAa,IAAI,MAAM;AAC7B,OAAI,eAAe,IAEjB,QAAO,OAAO,aACV,WAAW,OACX,OAAO,aACP,WAAW,OACX;YAGA,QAAQ,WAEV,QAAO,OAAO,aAAa,WAAW,OAAO,WAAW;OAGxD,QAAO,WAAW;AAItB,WAAQ,KAAK,KAAK;AAClB,OAAI;AACJ,gBAAa,IAAI;EAClB,WAAU,SAAS,OAAO,IAAI,IAAI,UAAU,SAAS,IAAI,OAAO,IAE/D;CAEH;CAGD,MAAM,gBAAgB,SAAS,MAAM,WAAW;AAChD,SAAQ,KAAK,cAAc,QAAQ,OAAO,IAAI,CAAC,QAAQ,OAAO,IAAI,CAAC;AAEnE,QAAO;AACR;;;;;;;;AASD,SAAgB,cACdC,UACAC,QACW;CACX,MAAM,OAAO,CAAE;AACf,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,OAAK,KAAK,SAAS,GAAG;AACtB,MAAI,IAAI,OAAO,OAAQ,MAAK,KAAK,OAAO,GAAG;CAC5C;AACD,QAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.1.0-dev.337+e8eb9c7d",
3
+ "version": "1.1.0-dev.338+557a49e7",
4
4
  "description": "Simple logging library with zero dependencies for Deno/Node.js/Bun/browsers",
5
5
  "keywords": [
6
6
  "logging",
@@ -852,3 +852,201 @@ test("LogMethod", () => {
852
852
  _method = ctx.error;
853
853
  _method = ctx.fatal;
854
854
  });
855
+
856
+ test("Logger.emit() with custom timestamp", () => {
857
+ const logger = getLogger(["test", "emit"]);
858
+ const records: LogRecord[] = [];
859
+ const sink: Sink = (record) => records.push(record);
860
+
861
+ try {
862
+ (logger as LoggerImpl).sinks.push(sink);
863
+
864
+ const customTimestamp = Date.now() - 60000; // 1 minute ago
865
+ logger.emit({
866
+ timestamp: customTimestamp,
867
+ level: "info",
868
+ message: ["Custom message with", "value"],
869
+ rawMessage: "Custom message with {value}",
870
+ properties: { value: "test", source: "external" },
871
+ });
872
+
873
+ assertEquals(records.length, 1);
874
+ assertEquals(records[0].category, ["test", "emit"]);
875
+ assertEquals(records[0].level, "info");
876
+ assertEquals(records[0].timestamp, customTimestamp);
877
+ assertEquals(records[0].message, ["Custom message with", "value"]);
878
+ assertEquals(records[0].rawMessage, "Custom message with {value}");
879
+ assertEquals(records[0].properties, { value: "test", source: "external" });
880
+ } finally {
881
+ (logger as LoggerImpl).reset();
882
+ }
883
+ });
884
+
885
+ test("Logger.emit() preserves all fields", () => {
886
+ const logger = getLogger("emit-test");
887
+ const records: LogRecord[] = [];
888
+ const sink: Sink = (record) => records.push(record);
889
+
890
+ try {
891
+ (logger as LoggerImpl).sinks.push(sink);
892
+
893
+ const testTimestamp = 1672531200000; // Fixed timestamp
894
+ const testMessage = ["Log from", "Kafka", "at", "partition 0"];
895
+ const testRawMessage =
896
+ "Log from {source} at {location} partition {partition}";
897
+ const testProperties = {
898
+ partition: 0,
899
+ offset: 12345,
900
+ topic: "test-topic",
901
+ source: "kafka",
902
+ };
903
+
904
+ logger.emit({
905
+ timestamp: testTimestamp,
906
+ level: "debug",
907
+ message: testMessage,
908
+ rawMessage: testRawMessage,
909
+ properties: testProperties,
910
+ });
911
+
912
+ assertEquals(records.length, 1);
913
+ const record = records[0];
914
+ assertEquals(record.category, ["emit-test"]);
915
+ assertEquals(record.level, "debug");
916
+ assertEquals(record.timestamp, testTimestamp);
917
+ assertEquals(record.message, testMessage);
918
+ assertEquals(record.rawMessage, testRawMessage);
919
+ assertEquals(record.properties, testProperties);
920
+ } finally {
921
+ (logger as LoggerImpl).reset();
922
+ }
923
+ });
924
+
925
+ test("LoggerCtx.emit() merges contextual properties", () => {
926
+ const logger = getLogger("ctx-emit");
927
+ const ctx = logger.with({ requestId: "req-123", userId: "user-456" });
928
+ const records: LogRecord[] = [];
929
+ const sink: Sink = (record) => records.push(record);
930
+
931
+ try {
932
+ (logger as LoggerImpl).sinks.push(sink);
933
+
934
+ ctx.emit({
935
+ timestamp: Date.now(),
936
+ level: "warning",
937
+ message: ["External warning from", "system"],
938
+ rawMessage: "External warning from {system}",
939
+ properties: { system: "external", priority: "high" },
940
+ });
941
+
942
+ assertEquals(records.length, 1);
943
+ const record = records[0];
944
+ assertEquals(record.category, ["ctx-emit"]);
945
+ assertEquals(record.level, "warning");
946
+ assertEquals(record.properties, {
947
+ system: "external",
948
+ priority: "high",
949
+ requestId: "req-123",
950
+ userId: "user-456",
951
+ });
952
+ } finally {
953
+ (logger as LoggerImpl).reset();
954
+ }
955
+ });
956
+
957
+ test("LoggerCtx.emit() record properties override context properties", () => {
958
+ const logger = getLogger("override-test");
959
+ const ctx = logger.with({ source: "context", shared: "from-context" });
960
+ const records: LogRecord[] = [];
961
+ const sink: Sink = (record) => records.push(record);
962
+
963
+ try {
964
+ (logger as LoggerImpl).sinks.push(sink);
965
+
966
+ ctx.emit({
967
+ timestamp: Date.now(),
968
+ level: "error",
969
+ message: ["Override test"],
970
+ rawMessage: "Override test",
971
+ properties: { source: "record", priority: "critical" },
972
+ });
973
+
974
+ assertEquals(records.length, 1);
975
+ const record = records[0];
976
+ assertEquals(record.properties, {
977
+ source: "record", // record properties override context
978
+ shared: "from-context", // context properties are preserved
979
+ priority: "critical",
980
+ });
981
+ } finally {
982
+ (logger as LoggerImpl).reset();
983
+ }
984
+ });
985
+
986
+ test("Logger.emit() respects filters", () => {
987
+ const logger = getLogger("filtered-emit");
988
+ const records: LogRecord[] = [];
989
+ const sink: Sink = (record) => records.push(record);
990
+
991
+ try {
992
+ (logger as LoggerImpl).sinks.push(sink);
993
+ (logger as LoggerImpl).filters.push((record) => record.level !== "debug");
994
+
995
+ // This should be filtered out
996
+ logger.emit({
997
+ timestamp: Date.now(),
998
+ level: "debug",
999
+ message: ["Debug message"],
1000
+ rawMessage: "Debug message",
1001
+ properties: {},
1002
+ });
1003
+
1004
+ // This should pass through
1005
+ logger.emit({
1006
+ timestamp: Date.now(),
1007
+ level: "info",
1008
+ message: ["Info message"],
1009
+ rawMessage: "Info message",
1010
+ properties: {},
1011
+ });
1012
+
1013
+ assertEquals(records.length, 1);
1014
+ assertEquals(records[0].level, "info");
1015
+ } finally {
1016
+ (logger as LoggerImpl).reset();
1017
+ }
1018
+ });
1019
+
1020
+ test("Logger.emit() respects log level threshold", () => {
1021
+ const logger = getLogger("level-emit");
1022
+ const records: LogRecord[] = [];
1023
+ const sink: Sink = (record) => records.push(record);
1024
+
1025
+ try {
1026
+ (logger as LoggerImpl).sinks.push(sink);
1027
+ (logger as LoggerImpl).lowestLevel = "warning";
1028
+
1029
+ // This should be filtered out (below threshold)
1030
+ logger.emit({
1031
+ timestamp: Date.now(),
1032
+ level: "info",
1033
+ message: ["Info message"],
1034
+ rawMessage: "Info message",
1035
+ properties: {},
1036
+ });
1037
+
1038
+ // This should pass through (at threshold)
1039
+ logger.emit({
1040
+ timestamp: Date.now(),
1041
+ level: "warning",
1042
+ message: ["Warning message"],
1043
+ rawMessage: "Warning message",
1044
+ properties: {},
1045
+ });
1046
+
1047
+ assertEquals(records.length, 1);
1048
+ assertEquals(records[0].level, "warning");
1049
+ } finally {
1050
+ (logger as LoggerImpl).reset();
1051
+ }
1052
+ });
package/src/logger.ts CHANGED
@@ -685,6 +685,37 @@ export interface Logger {
685
685
  * @throws {TypeError} If no log record was made inside the callback.
686
686
  */
687
687
  fatal(callback: LogCallback): void;
688
+
689
+ /**
690
+ * Emits a log record with custom fields while using this logger's
691
+ * category.
692
+ *
693
+ * This is a low-level API for integration scenarios where you need full
694
+ * control over the log record, particularly for preserving timestamps
695
+ * from external systems.
696
+ *
697
+ * ```typescript
698
+ * const logger = getLogger(["my-app", "integration"]);
699
+ *
700
+ * // Emit a log with a custom timestamp
701
+ * logger.emit({
702
+ * timestamp: kafkaLog.originalTimestamp,
703
+ * level: "info",
704
+ * message: [kafkaLog.message],
705
+ * rawMessage: kafkaLog.message,
706
+ * properties: {
707
+ * source: "kafka",
708
+ * partition: kafkaLog.partition,
709
+ * offset: kafkaLog.offset,
710
+ * },
711
+ * });
712
+ * ```
713
+ *
714
+ * @param record Log record without category field (category comes from
715
+ * the logger instance)
716
+ * @since 1.1.0
717
+ */
718
+ emit(record: Omit<LogRecord, "category">): void;
688
719
  }
689
720
 
690
721
  /**
@@ -887,25 +918,34 @@ export class LoggerImpl implements Logger {
887
918
  for (const sink of this.sinks) yield sink;
888
919
  }
889
920
 
890
- emit(record: LogRecord, bypassSinks?: Set<Sink>): void {
921
+ emit(record: Omit<LogRecord, "category">): void;
922
+ emit(record: LogRecord, bypassSinks?: Set<Sink>): void;
923
+ emit(
924
+ record: Omit<LogRecord, "category"> | LogRecord,
925
+ bypassSinks?: Set<Sink>,
926
+ ): void {
927
+ const fullRecord: LogRecord = "category" in record
928
+ ? record as LogRecord
929
+ : { ...record, category: this.category };
930
+
891
931
  if (
892
932
  this.lowestLevel === null ||
893
- compareLogLevel(record.level, this.lowestLevel) < 0 ||
894
- !this.filter(record)
933
+ compareLogLevel(fullRecord.level, this.lowestLevel) < 0 ||
934
+ !this.filter(fullRecord)
895
935
  ) {
896
936
  return;
897
937
  }
898
- for (const sink of this.getSinks(record.level)) {
938
+ for (const sink of this.getSinks(fullRecord.level)) {
899
939
  if (bypassSinks?.has(sink)) continue;
900
940
  try {
901
- sink(record);
941
+ sink(fullRecord);
902
942
  } catch (error) {
903
943
  const bypassSinks2 = new Set(bypassSinks);
904
944
  bypassSinks2.add(sink);
905
945
  metaLogger.log(
906
946
  "fatal",
907
947
  "Failed to emit a log record to sink {sink}: {error}",
908
- { sink, error, record },
948
+ { sink, error, record: fullRecord },
909
949
  bypassSinks2,
910
950
  );
911
951
  }
@@ -1198,6 +1238,14 @@ export class LoggerCtx implements Logger {
1198
1238
  this.logger.logTemplate(level, messageTemplate, values, this.properties);
1199
1239
  }
1200
1240
 
1241
+ emit(record: Omit<LogRecord, "category">): void {
1242
+ const recordWithContext = {
1243
+ ...record,
1244
+ properties: { ...this.properties, ...record.properties },
1245
+ };
1246
+ this.logger.emit(recordWithContext);
1247
+ }
1248
+
1201
1249
  trace(
1202
1250
  message:
1203
1251
  | TemplateStringsArray