@logtape/logtape 1.3.0-dev.376 → 1.3.0-dev.378

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/README.md CHANGED
@@ -5,6 +5,7 @@ LogTape
5
5
 
6
6
  [![JSR][JSR badge]][JSR]
7
7
  [![npm][npm badge]][npm]
8
+ [![Bundlephobia][Bundlephobia badge]][Bundlephobia]
8
9
  [![GitHub Actions][GitHub Actions badge]][GitHub Actions]
9
10
  [![Codecov][Codecov badge]][Codecov]
10
11
 
@@ -46,6 +47,8 @@ The highlights of LogTape are:
46
47
  [JSR badge]: https://jsr.io/badges/@logtape/logtape
47
48
  [npm]: https://www.npmjs.com/package/@logtape/logtape
48
49
  [npm badge]: https://img.shields.io/npm/v/@logtape/logtape?logo=npm
50
+ [Bundlephobia]: https://bundlephobia.com/package/@logtape/logtape
51
+ [Bundlephobia badge]: https://badgen.net/bundlephobia/dependency-count/@logtape/logtape
49
52
  [GitHub Actions]: https://github.com/dahlia/logtape/actions/workflows/main.yaml
50
53
  [GitHub Actions badge]: https://github.com/dahlia/logtape/actions/workflows/main.yaml/badge.svg
51
54
  [Codecov]: https://codecov.io/gh/dahlia/logtape
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.3.0-dev.376+3abddd8c",
3
+ "version": "1.3.0-dev.378+36427b63",
4
4
  "license": "MIT",
5
5
  "exports": "./src/mod.ts",
6
6
  "imports": {
package/dist/context.cjs CHANGED
@@ -2,6 +2,10 @@ const require_logger = require('./logger.cjs');
2
2
 
3
3
  //#region src/context.ts
4
4
  /**
5
+ * Internal symbol for storing category prefix in context.
6
+ */
7
+ const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
8
+ /**
5
9
  * Runs a callback with the given implicit context. Every single log record
6
10
  * in the callback will have the given context.
7
11
  *
@@ -25,6 +29,79 @@ function withContext(context, callback) {
25
29
  ...context
26
30
  }, callback);
27
31
  }
32
+ /**
33
+ * Gets the current category prefix from context local storage.
34
+ * @returns The current category prefix, or an empty array if not set.
35
+ * @since 1.3.0
36
+ */
37
+ function getCategoryPrefix() {
38
+ const rootLogger = require_logger.LoggerImpl.getLogger();
39
+ const store = rootLogger.contextLocalStorage?.getStore();
40
+ if (store == null) return [];
41
+ const prefix = store[categoryPrefixSymbol];
42
+ return Array.isArray(prefix) ? prefix : [];
43
+ }
44
+ /**
45
+ * Gets the current implicit context from context local storage, excluding
46
+ * internal symbol keys (like category prefix).
47
+ * @returns The current implicit context without internal symbol keys.
48
+ * @since 1.3.0
49
+ */
50
+ function getImplicitContext() {
51
+ const rootLogger = require_logger.LoggerImpl.getLogger();
52
+ const store = rootLogger.contextLocalStorage?.getStore();
53
+ if (store == null) return {};
54
+ const result = {};
55
+ for (const key of Object.keys(store)) result[key] = store[key];
56
+ return result;
57
+ }
58
+ /**
59
+ * Runs a callback with the given category prefix prepended to all log
60
+ * categories within the callback context.
61
+ *
62
+ * This is useful for SDKs or libraries that want to add their own category
63
+ * as a prefix to logs from their internal dependencies.
64
+ *
65
+ * If no `contextLocalStorage` is configured, this function does nothing and
66
+ * just returns the return value of the callback. It also logs a warning to
67
+ * the `["logtape", "meta"]` logger in this case.
68
+ *
69
+ * @example Basic usage
70
+ * ```typescript
71
+ * import { getLogger, withCategoryPrefix } from "@logtape/logtape";
72
+ *
73
+ * export function sdkFunction() {
74
+ * return withCategoryPrefix(["my-sdk"], () => {
75
+ * // Any logs from internal libraries within this context
76
+ * // will have ["my-sdk"] prepended to their category
77
+ * return internalLibraryFunction();
78
+ * });
79
+ * }
80
+ * ```
81
+ *
82
+ * @param prefix The category prefix to prepend. Can be a string or an array
83
+ * of strings.
84
+ * @param callback The callback to run.
85
+ * @returns The return value of the callback.
86
+ * @since 1.3.0
87
+ */
88
+ function withCategoryPrefix(prefix, callback) {
89
+ const rootLogger = require_logger.LoggerImpl.getLogger();
90
+ if (rootLogger.contextLocalStorage == null) {
91
+ require_logger.LoggerImpl.getLogger(["logtape", "meta"]).warn("Context-local storage is not configured. Specify contextLocalStorage option in the configure() function.");
92
+ return callback();
93
+ }
94
+ const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
95
+ const parentPrefix = getCategoryPrefix();
96
+ const newPrefix = typeof prefix === "string" ? [prefix] : [...prefix];
97
+ return rootLogger.contextLocalStorage.run({
98
+ ...parentContext,
99
+ [categoryPrefixSymbol]: [...parentPrefix, ...newPrefix]
100
+ }, callback);
101
+ }
28
102
 
29
103
  //#endregion
104
+ exports.getCategoryPrefix = getCategoryPrefix;
105
+ exports.getImplicitContext = getImplicitContext;
106
+ exports.withCategoryPrefix = withCategoryPrefix;
30
107
  exports.withContext = withContext;
@@ -33,7 +33,44 @@ interface ContextLocalStorage<T> {
33
33
  * @since 0.7.0
34
34
  */
35
35
  declare function withContext<T>(context: Record<string, unknown>, callback: () => T): T;
36
+ /**
37
+ * Gets the current category prefix from context local storage.
38
+ * @returns The current category prefix, or an empty array if not set.
39
+ * @since 1.3.0
40
+ */
41
+
42
+ /**
43
+ * Runs a callback with the given category prefix prepended to all log
44
+ * categories within the callback context.
45
+ *
46
+ * This is useful for SDKs or libraries that want to add their own category
47
+ * as a prefix to logs from their internal dependencies.
48
+ *
49
+ * If no `contextLocalStorage` is configured, this function does nothing and
50
+ * just returns the return value of the callback. It also logs a warning to
51
+ * the `["logtape", "meta"]` logger in this case.
52
+ *
53
+ * @example Basic usage
54
+ * ```typescript
55
+ * import { getLogger, withCategoryPrefix } from "@logtape/logtape";
56
+ *
57
+ * export function sdkFunction() {
58
+ * return withCategoryPrefix(["my-sdk"], () => {
59
+ * // Any logs from internal libraries within this context
60
+ * // will have ["my-sdk"] prepended to their category
61
+ * return internalLibraryFunction();
62
+ * });
63
+ * }
64
+ * ```
65
+ *
66
+ * @param prefix The category prefix to prepend. Can be a string or an array
67
+ * of strings.
68
+ * @param callback The callback to run.
69
+ * @returns The return value of the callback.
70
+ * @since 1.3.0
71
+ */
72
+ declare function withCategoryPrefix<T>(prefix: string | readonly string[], callback: () => T): T;
36
73
  //# sourceMappingURL=context.d.ts.map
37
74
  //#endregion
38
- export { ContextLocalStorage, withContext };
75
+ export { ContextLocalStorage, withCategoryPrefix, withContext };
39
76
  //# sourceMappingURL=context.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;AAcc,UAdG,mBAcH,CAAA,CAAA,CAAA,CAAA;EAAC;AAef;;;;;EAGI,GAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAzBY,CAyBZ,EAAA,QAAA,EAAA,GAAA,GAzB+B,CAyB/B,CAAA,EAzBmC,CAyBnC;;;;;;cAlBU;;;;;;;;;;;;;;iBAeE,wBACL,yCACO,IACf"}
1
+ {"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;AAeA;;;;;AAcc,UAdG,mBAcH,CAAA,CAAA,CAAA,CAAA;EAAC;AAef;;;;;EAGI,GAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAzBY,CAyBZ,EAAA,QAAA,EAAA,GAAA,GAzB+B,CAyB/B,CAAA,EAzBmC,CAyBnC;EA6EY;;;;AAGZ;cAlGU;;;;;;;;;;;;;;iBAeE,wBACL,yCACO,IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6Ea,0EAEE,IACf"}
package/dist/context.d.ts CHANGED
@@ -33,7 +33,44 @@ interface ContextLocalStorage<T> {
33
33
  * @since 0.7.0
34
34
  */
35
35
  declare function withContext<T>(context: Record<string, unknown>, callback: () => T): T;
36
+ /**
37
+ * Gets the current category prefix from context local storage.
38
+ * @returns The current category prefix, or an empty array if not set.
39
+ * @since 1.3.0
40
+ */
41
+
42
+ /**
43
+ * Runs a callback with the given category prefix prepended to all log
44
+ * categories within the callback context.
45
+ *
46
+ * This is useful for SDKs or libraries that want to add their own category
47
+ * as a prefix to logs from their internal dependencies.
48
+ *
49
+ * If no `contextLocalStorage` is configured, this function does nothing and
50
+ * just returns the return value of the callback. It also logs a warning to
51
+ * the `["logtape", "meta"]` logger in this case.
52
+ *
53
+ * @example Basic usage
54
+ * ```typescript
55
+ * import { getLogger, withCategoryPrefix } from "@logtape/logtape";
56
+ *
57
+ * export function sdkFunction() {
58
+ * return withCategoryPrefix(["my-sdk"], () => {
59
+ * // Any logs from internal libraries within this context
60
+ * // will have ["my-sdk"] prepended to their category
61
+ * return internalLibraryFunction();
62
+ * });
63
+ * }
64
+ * ```
65
+ *
66
+ * @param prefix The category prefix to prepend. Can be a string or an array
67
+ * of strings.
68
+ * @param callback The callback to run.
69
+ * @returns The return value of the callback.
70
+ * @since 1.3.0
71
+ */
72
+ declare function withCategoryPrefix<T>(prefix: string | readonly string[], callback: () => T): T;
36
73
  //# sourceMappingURL=context.d.ts.map
37
74
  //#endregion
38
- export { ContextLocalStorage, withContext };
75
+ export { ContextLocalStorage, withCategoryPrefix, withContext };
39
76
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;AAcc,UAdG,mBAcH,CAAA,CAAA,CAAA,CAAA;EAAC;AAef;;;;;EAGI,GAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAzBY,CAyBZ,EAAA,QAAA,EAAA,GAAA,GAzB+B,CAyB/B,CAAA,EAzBmC,CAyBnC;;;;;;cAlBU;;;;;;;;;;;;;;iBAeE,wBACL,yCACO,IACf"}
1
+ {"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"sourcesContent":[],"mappings":";;AAeA;;;;;AAcc,UAdG,mBAcH,CAAA,CAAA,CAAA,CAAA;EAAC;AAef;;;;;EAGI,GAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAzBY,CAyBZ,EAAA,QAAA,EAAA,GAAA,GAzB+B,CAyB/B,CAAA,EAzBmC,CAyBnC;EA6EY;;;;AAGZ;cAlGU;;;;;;;;;;;;;;iBAeE,wBACL,yCACO,IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6Ea,0EAEE,IACf"}
package/dist/context.js CHANGED
@@ -2,6 +2,10 @@ import { LoggerImpl } from "./logger.js";
2
2
 
3
3
  //#region src/context.ts
4
4
  /**
5
+ * Internal symbol for storing category prefix in context.
6
+ */
7
+ const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
8
+ /**
5
9
  * Runs a callback with the given implicit context. Every single log record
6
10
  * in the callback will have the given context.
7
11
  *
@@ -25,7 +29,77 @@ function withContext(context, callback) {
25
29
  ...context
26
30
  }, callback);
27
31
  }
32
+ /**
33
+ * Gets the current category prefix from context local storage.
34
+ * @returns The current category prefix, or an empty array if not set.
35
+ * @since 1.3.0
36
+ */
37
+ function getCategoryPrefix() {
38
+ const rootLogger = LoggerImpl.getLogger();
39
+ const store = rootLogger.contextLocalStorage?.getStore();
40
+ if (store == null) return [];
41
+ const prefix = store[categoryPrefixSymbol];
42
+ return Array.isArray(prefix) ? prefix : [];
43
+ }
44
+ /**
45
+ * Gets the current implicit context from context local storage, excluding
46
+ * internal symbol keys (like category prefix).
47
+ * @returns The current implicit context without internal symbol keys.
48
+ * @since 1.3.0
49
+ */
50
+ function getImplicitContext() {
51
+ const rootLogger = LoggerImpl.getLogger();
52
+ const store = rootLogger.contextLocalStorage?.getStore();
53
+ if (store == null) return {};
54
+ const result = {};
55
+ for (const key of Object.keys(store)) result[key] = store[key];
56
+ return result;
57
+ }
58
+ /**
59
+ * Runs a callback with the given category prefix prepended to all log
60
+ * categories within the callback context.
61
+ *
62
+ * This is useful for SDKs or libraries that want to add their own category
63
+ * as a prefix to logs from their internal dependencies.
64
+ *
65
+ * If no `contextLocalStorage` is configured, this function does nothing and
66
+ * just returns the return value of the callback. It also logs a warning to
67
+ * the `["logtape", "meta"]` logger in this case.
68
+ *
69
+ * @example Basic usage
70
+ * ```typescript
71
+ * import { getLogger, withCategoryPrefix } from "@logtape/logtape";
72
+ *
73
+ * export function sdkFunction() {
74
+ * return withCategoryPrefix(["my-sdk"], () => {
75
+ * // Any logs from internal libraries within this context
76
+ * // will have ["my-sdk"] prepended to their category
77
+ * return internalLibraryFunction();
78
+ * });
79
+ * }
80
+ * ```
81
+ *
82
+ * @param prefix The category prefix to prepend. Can be a string or an array
83
+ * of strings.
84
+ * @param callback The callback to run.
85
+ * @returns The return value of the callback.
86
+ * @since 1.3.0
87
+ */
88
+ function withCategoryPrefix(prefix, callback) {
89
+ const rootLogger = LoggerImpl.getLogger();
90
+ if (rootLogger.contextLocalStorage == null) {
91
+ LoggerImpl.getLogger(["logtape", "meta"]).warn("Context-local storage is not configured. Specify contextLocalStorage option in the configure() function.");
92
+ return callback();
93
+ }
94
+ const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
95
+ const parentPrefix = getCategoryPrefix();
96
+ const newPrefix = typeof prefix === "string" ? [prefix] : [...prefix];
97
+ return rootLogger.contextLocalStorage.run({
98
+ ...parentContext,
99
+ [categoryPrefixSymbol]: [...parentPrefix, ...newPrefix]
100
+ }, callback);
101
+ }
28
102
 
29
103
  //#endregion
30
- export { withContext };
104
+ export { getCategoryPrefix, getImplicitContext, withCategoryPrefix, withContext };
31
105
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["context: Record<string, unknown>","callback: () => T"],"sources":["../src/context.ts"],"sourcesContent":["import { LoggerImpl } from \"./logger.ts\";\n\n/**\n * A generic interface for a context-local storage. It resembles\n * the {@link AsyncLocalStorage} API from Node.js.\n * @template T The type of the context-local store.\n * @since 0.7.0\n */\nexport interface ContextLocalStorage<T> {\n /**\n * Runs a callback with the given store as the context-local store.\n * @param store The store to use as the context-local store.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n */\n run<R>(store: T, callback: () => R): R;\n\n /**\n * Returns the current context-local store.\n * @returns The current context-local store, or `undefined` if there is no\n * store.\n */\n getStore(): T | undefined;\n}\n\n/**\n * Runs a callback with the given implicit context. Every single log record\n * in the callback will have the given context.\n *\n * If no `contextLocalStorage` is configured, this function does nothing and\n * just returns the return value of the callback. It also logs a warning to\n * the `[\"logtape\", \"meta\"]` logger in this case.\n * @param context The context to inject.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n * @since 0.7.0\n */\nexport function withContext<T>(\n context: Record<string, unknown>,\n callback: () => T,\n): T {\n const rootLogger = LoggerImpl.getLogger();\n if (rootLogger.contextLocalStorage == null) {\n LoggerImpl.getLogger([\"logtape\", \"meta\"]).warn(\n \"Context-local storage is not configured. \" +\n \"Specify contextLocalStorage option in the configure() function.\",\n );\n return callback();\n }\n const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};\n return rootLogger.contextLocalStorage.run(\n { ...parentContext, ...context },\n callback,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,SAAgB,YACdA,SACAC,UACG;CACH,MAAM,aAAa,WAAW,WAAW;AACzC,KAAI,WAAW,uBAAuB,MAAM;AAC1C,aAAW,UAAU,CAAC,WAAW,MAAO,EAAC,CAAC,KACxC,4GAED;AACD,SAAO,UAAU;CAClB;CACD,MAAM,gBAAgB,WAAW,oBAAoB,UAAU,IAAI,CAAE;AACrE,QAAO,WAAW,oBAAoB,IACpC;EAAE,GAAG;EAAe,GAAG;CAAS,GAChC,SACD;AACF"}
1
+ {"version":3,"file":"context.js","names":["categoryPrefixSymbol: unique symbol","context: Record<string, unknown>","callback: () => T","result: Record<string, unknown>","prefix: string | readonly string[]"],"sources":["../src/context.ts"],"sourcesContent":["import { LoggerImpl } from \"./logger.ts\";\n\n/**\n * Internal symbol for storing category prefix in context.\n */\nconst categoryPrefixSymbol: unique symbol = Symbol.for(\n \"logtape.categoryPrefix\",\n) as typeof categoryPrefixSymbol;\n\n/**\n * A generic interface for a context-local storage. It resembles\n * the {@link AsyncLocalStorage} API from Node.js.\n * @template T The type of the context-local store.\n * @since 0.7.0\n */\nexport interface ContextLocalStorage<T> {\n /**\n * Runs a callback with the given store as the context-local store.\n * @param store The store to use as the context-local store.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n */\n run<R>(store: T, callback: () => R): R;\n\n /**\n * Returns the current context-local store.\n * @returns The current context-local store, or `undefined` if there is no\n * store.\n */\n getStore(): T | undefined;\n}\n\n/**\n * Runs a callback with the given implicit context. Every single log record\n * in the callback will have the given context.\n *\n * If no `contextLocalStorage` is configured, this function does nothing and\n * just returns the return value of the callback. It also logs a warning to\n * the `[\"logtape\", \"meta\"]` logger in this case.\n * @param context The context to inject.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n * @since 0.7.0\n */\nexport function withContext<T>(\n context: Record<string, unknown>,\n callback: () => T,\n): T {\n const rootLogger = LoggerImpl.getLogger();\n if (rootLogger.contextLocalStorage == null) {\n LoggerImpl.getLogger([\"logtape\", \"meta\"]).warn(\n \"Context-local storage is not configured. \" +\n \"Specify contextLocalStorage option in the configure() function.\",\n );\n return callback();\n }\n const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};\n return rootLogger.contextLocalStorage.run(\n { ...parentContext, ...context },\n callback,\n );\n}\n\n/**\n * Gets the current category prefix from context local storage.\n * @returns The current category prefix, or an empty array if not set.\n * @since 1.3.0\n */\nexport function getCategoryPrefix(): readonly string[] {\n const rootLogger = LoggerImpl.getLogger();\n const store = rootLogger.contextLocalStorage?.getStore();\n if (store == null) return [];\n const prefix = store[categoryPrefixSymbol as unknown as string];\n return Array.isArray(prefix) ? prefix : [];\n}\n\n/**\n * Gets the current implicit context from context local storage, excluding\n * internal symbol keys (like category prefix).\n * @returns The current implicit context without internal symbol keys.\n * @since 1.3.0\n */\nexport function getImplicitContext(): Record<string, unknown> {\n const rootLogger = LoggerImpl.getLogger();\n const store = rootLogger.contextLocalStorage?.getStore();\n if (store == null) return {};\n // Filter out symbol keys (like categoryPrefixSymbol)\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(store)) {\n result[key] = store[key];\n }\n return result;\n}\n\n/**\n * Runs a callback with the given category prefix prepended to all log\n * categories within the callback context.\n *\n * This is useful for SDKs or libraries that want to add their own category\n * as a prefix to logs from their internal dependencies.\n *\n * If no `contextLocalStorage` is configured, this function does nothing and\n * just returns the return value of the callback. It also logs a warning to\n * the `[\"logtape\", \"meta\"]` logger in this case.\n *\n * @example Basic usage\n * ```typescript\n * import { getLogger, withCategoryPrefix } from \"@logtape/logtape\";\n *\n * export function sdkFunction() {\n * return withCategoryPrefix([\"my-sdk\"], () => {\n * // Any logs from internal libraries within this context\n * // will have [\"my-sdk\"] prepended to their category\n * return internalLibraryFunction();\n * });\n * }\n * ```\n *\n * @param prefix The category prefix to prepend. Can be a string or an array\n * of strings.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n * @since 1.3.0\n */\nexport function withCategoryPrefix<T>(\n prefix: string | readonly string[],\n callback: () => T,\n): T {\n const rootLogger = LoggerImpl.getLogger();\n if (rootLogger.contextLocalStorage == null) {\n LoggerImpl.getLogger([\"logtape\", \"meta\"]).warn(\n \"Context-local storage is not configured. \" +\n \"Specify contextLocalStorage option in the configure() function.\",\n );\n return callback();\n }\n const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};\n const parentPrefix = getCategoryPrefix();\n const newPrefix = typeof prefix === \"string\" ? [prefix] : [...prefix];\n return rootLogger.contextLocalStorage.run(\n {\n ...parentContext,\n [categoryPrefixSymbol as unknown as string]: [\n ...parentPrefix,\n ...newPrefix,\n ],\n },\n callback,\n );\n}\n"],"mappings":";;;;;;AAKA,MAAMA,uBAAsC,OAAO,IACjD,yBACD;;;;;;;;;;;;;AAqCD,SAAgB,YACdC,SACAC,UACG;CACH,MAAM,aAAa,WAAW,WAAW;AACzC,KAAI,WAAW,uBAAuB,MAAM;AAC1C,aAAW,UAAU,CAAC,WAAW,MAAO,EAAC,CAAC,KACxC,4GAED;AACD,SAAO,UAAU;CAClB;CACD,MAAM,gBAAgB,WAAW,oBAAoB,UAAU,IAAI,CAAE;AACrE,QAAO,WAAW,oBAAoB,IACpC;EAAE,GAAG;EAAe,GAAG;CAAS,GAChC,SACD;AACF;;;;;;AAOD,SAAgB,oBAAuC;CACrD,MAAM,aAAa,WAAW,WAAW;CACzC,MAAM,QAAQ,WAAW,qBAAqB,UAAU;AACxD,KAAI,SAAS,KAAM,QAAO,CAAE;CAC5B,MAAM,SAAS,MAAM;AACrB,QAAO,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAE;AAC3C;;;;;;;AAQD,SAAgB,qBAA8C;CAC5D,MAAM,aAAa,WAAW,WAAW;CACzC,MAAM,QAAQ,WAAW,qBAAqB,UAAU;AACxD,KAAI,SAAS,KAAM,QAAO,CAAE;CAE5B,MAAMC,SAAkC,CAAE;AAC1C,MAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CAClC,QAAO,OAAO,MAAM;AAEtB,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCD,SAAgB,mBACdC,QACAF,UACG;CACH,MAAM,aAAa,WAAW,WAAW;AACzC,KAAI,WAAW,uBAAuB,MAAM;AAC1C,aAAW,UAAU,CAAC,WAAW,MAAO,EAAC,CAAC,KACxC,4GAED;AACD,SAAO,UAAU;CAClB;CACD,MAAM,gBAAgB,WAAW,oBAAoB,UAAU,IAAI,CAAE;CACrE,MAAM,eAAe,mBAAmB;CACxC,MAAM,mBAAmB,WAAW,WAAW,CAAC,MAAO,IAAG,CAAC,GAAG,MAAO;AACrE,QAAO,WAAW,oBAAoB,IACpC;EACE,GAAG;GACF,uBAA4C,CAC3C,GAAG,cACH,GAAG,SACJ;CACF,GACD,SACD;AACF"}
package/dist/logger.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const require_context = require('./context.cjs');
1
2
  const require_level = require('./level.cjs');
2
3
 
3
4
  //#region src/logger.ts
@@ -95,10 +96,16 @@ var LoggerImpl = class LoggerImpl {
95
96
  for (const sink of this.sinks) yield sink;
96
97
  }
97
98
  emit(record, bypassSinks) {
98
- const fullRecord = "category" in record ? record : {
99
- ...record,
100
- category: this.category
99
+ const categoryPrefix = require_context.getCategoryPrefix();
100
+ const baseCategory = "category" in record ? record.category : this.category;
101
+ const fullCategory = categoryPrefix.length > 0 ? [...categoryPrefix, ...baseCategory] : baseCategory;
102
+ const descriptors = Object.getOwnPropertyDescriptors(record);
103
+ descriptors.category = {
104
+ value: fullCategory,
105
+ enumerable: true,
106
+ configurable: true
101
107
  };
108
+ const fullRecord = Object.defineProperties({}, descriptors);
102
109
  if (this.lowestLevel === null || require_level.compareLogLevel(fullRecord.level, this.lowestLevel) < 0 || !this.filter(fullRecord)) return;
103
110
  for (const sink of this.getSinks(fullRecord.level)) {
104
111
  if (bypassSinks?.has(sink)) continue;
@@ -116,7 +123,7 @@ var LoggerImpl = class LoggerImpl {
116
123
  }
117
124
  }
118
125
  log(level, rawMessage, properties, bypassSinks) {
119
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
126
+ const implicitContext = require_context.getImplicitContext();
120
127
  let cachedProps = void 0;
121
128
  const record = typeof properties === "function" ? {
122
129
  category: this.category,
@@ -150,7 +157,7 @@ var LoggerImpl = class LoggerImpl {
150
157
  this.emit(record, bypassSinks);
151
158
  }
152
159
  logLazily(level, callback, properties = {}) {
153
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
160
+ const implicitContext = require_context.getImplicitContext();
154
161
  let rawMessage = void 0;
155
162
  let msg = void 0;
156
163
  function realizeMessage() {
@@ -180,7 +187,7 @@ var LoggerImpl = class LoggerImpl {
180
187
  });
181
188
  }
182
189
  logTemplate(level, messageTemplate, values, properties = {}) {
183
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
190
+ const implicitContext = require_context.getImplicitContext();
184
191
  this.emit({
185
192
  category: this.category,
186
193
  level,
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;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B;;;;;;;;;;;;;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
@@ -1,3 +1,4 @@
1
+ import { getCategoryPrefix, getImplicitContext } from "./context.js";
1
2
  import { compareLogLevel } from "./level.js";
2
3
 
3
4
  //#region src/logger.ts
@@ -95,10 +96,16 @@ var LoggerImpl = class LoggerImpl {
95
96
  for (const sink of this.sinks) yield sink;
96
97
  }
97
98
  emit(record, bypassSinks) {
98
- const fullRecord = "category" in record ? record : {
99
- ...record,
100
- category: this.category
99
+ const categoryPrefix = getCategoryPrefix();
100
+ const baseCategory = "category" in record ? record.category : this.category;
101
+ const fullCategory = categoryPrefix.length > 0 ? [...categoryPrefix, ...baseCategory] : baseCategory;
102
+ const descriptors = Object.getOwnPropertyDescriptors(record);
103
+ descriptors.category = {
104
+ value: fullCategory,
105
+ enumerable: true,
106
+ configurable: true
101
107
  };
108
+ const fullRecord = Object.defineProperties({}, descriptors);
102
109
  if (this.lowestLevel === null || compareLogLevel(fullRecord.level, this.lowestLevel) < 0 || !this.filter(fullRecord)) return;
103
110
  for (const sink of this.getSinks(fullRecord.level)) {
104
111
  if (bypassSinks?.has(sink)) continue;
@@ -116,7 +123,7 @@ var LoggerImpl = class LoggerImpl {
116
123
  }
117
124
  }
118
125
  log(level, rawMessage, properties, bypassSinks) {
119
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
126
+ const implicitContext = getImplicitContext();
120
127
  let cachedProps = void 0;
121
128
  const record = typeof properties === "function" ? {
122
129
  category: this.category,
@@ -150,7 +157,7 @@ var LoggerImpl = class LoggerImpl {
150
157
  this.emit(record, bypassSinks);
151
158
  }
152
159
  logLazily(level, callback, properties = {}) {
153
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
160
+ const implicitContext = getImplicitContext();
154
161
  let rawMessage = void 0;
155
162
  let msg = void 0;
156
163
  function realizeMessage() {
@@ -180,7 +187,7 @@ var LoggerImpl = class LoggerImpl {
180
187
  });
181
188
  }
182
189
  logTemplate(level, messageTemplate, values, properties = {}) {
183
- const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
190
+ const implicitContext = getImplicitContext();
184
191
  this.emit({
185
192
  category: this.category,
186
193
  level,
@@ -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","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\">","key: string","obj: unknown","path: string","fromIndex: number","segment: string | number","current: unknown","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 * Check if a property access key contains nested access patterns.\n * @param key The property key to check.\n * @returns True if the key contains nested access patterns.\n */\nfunction isNestedAccess(key: string): boolean {\n return key.includes(\".\") || key.includes(\"[\") || key.includes(\"?.\");\n}\n\n/**\n * Safely access an own property from an object, blocking prototype pollution.\n *\n * @param obj The object to access the property from.\n * @param key The property key to access.\n * @returns The property value or undefined if not accessible.\n */\nfunction getOwnProperty(obj: unknown, key: string): unknown {\n // Block dangerous prototype keys\n if (key === \"__proto__\" || key === \"prototype\" || key === \"constructor\") {\n return undefined;\n }\n\n if ((typeof obj === \"object\" || typeof obj === \"function\") && obj !== null) {\n return Object.prototype.hasOwnProperty.call(obj, key)\n ? (obj as Record<string, unknown>)[key]\n : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Result of parsing a single segment from a property path.\n */\ninterface ParseSegmentResult {\n segment: string | number;\n nextIndex: number;\n}\n\n/**\n * Parse the next segment from a property path string.\n *\n * @param path The full property path string.\n * @param fromIndex The index to start parsing from.\n * @returns The parsed segment and next index, or null if parsing fails.\n */\nfunction parseNextSegment(\n path: string,\n fromIndex: number,\n): ParseSegmentResult | null {\n const len = path.length;\n let i = fromIndex;\n\n if (i >= len) return null;\n\n let segment: string | number;\n\n if (path[i] === \"[\") {\n // Bracket notation: [0] or [\"prop\"]\n i++;\n if (i >= len) return null;\n\n if (path[i] === '\"' || path[i] === \"'\") {\n // Quoted property name: [\"prop-name\"]\n const quote = path[i];\n i++;\n // Build segment with proper escape handling\n let segmentStr = \"\";\n while (i < len && path[i] !== quote) {\n if (path[i] === \"\\\\\") {\n i++; // Skip backslash\n if (i < len) {\n // Handle escape sequences according to JavaScript spec\n const escapeChar = path[i];\n switch (escapeChar) {\n case \"n\":\n segmentStr += \"\\n\";\n break;\n case \"t\":\n segmentStr += \"\\t\";\n break;\n case \"r\":\n segmentStr += \"\\r\";\n break;\n case \"b\":\n segmentStr += \"\\b\";\n break;\n case \"f\":\n segmentStr += \"\\f\";\n break;\n case \"v\":\n segmentStr += \"\\v\";\n break;\n case \"0\":\n segmentStr += \"\\0\";\n break;\n case \"\\\\\":\n segmentStr += \"\\\\\";\n break;\n case '\"':\n segmentStr += '\"';\n break;\n case \"'\":\n segmentStr += \"'\";\n break;\n case \"u\":\n // Unicode escape: \\uXXXX\n if (i + 4 < len) {\n const hex = path.slice(i + 1, i + 5);\n const codePoint = Number.parseInt(hex, 16);\n if (!Number.isNaN(codePoint)) {\n segmentStr += String.fromCharCode(codePoint);\n i += 4; // Skip the 4 hex digits\n } else {\n // Invalid unicode escape, keep as-is\n segmentStr += escapeChar;\n }\n } else {\n // Not enough characters for unicode escape\n segmentStr += escapeChar;\n }\n break;\n default:\n // For any other character after \\, just add it as-is\n segmentStr += escapeChar;\n }\n i++;\n }\n } else {\n segmentStr += path[i];\n i++;\n }\n }\n if (i >= len) return null;\n segment = segmentStr;\n i++; // Skip closing quote\n } else {\n // Array index: [0]\n const startIndex = i;\n while (\n i < len && path[i] !== \"]\" && path[i] !== \"'\" && path[i] !== '\"'\n ) {\n i++;\n }\n if (i >= len) return null;\n const indexStr = path.slice(startIndex, i);\n // Empty bracket is invalid\n if (indexStr.length === 0) return null;\n const indexNum = Number(indexStr);\n segment = Number.isNaN(indexNum) ? indexStr : indexNum;\n }\n\n // Skip closing bracket\n while (i < len && path[i] !== \"]\") i++;\n if (i < len) i++;\n } else {\n // Dot notation: prop\n const startIndex = i;\n while (\n i < len && path[i] !== \".\" && path[i] !== \"[\" && path[i] !== \"?\" &&\n path[i] !== \"]\"\n ) {\n i++;\n }\n segment = path.slice(startIndex, i);\n // Empty segment is invalid (e.g., leading dot, double dot, trailing dot)\n if (segment.length === 0) return null;\n }\n\n // Skip dot separator\n if (i < len && path[i] === \".\") i++;\n\n return { segment, nextIndex: i };\n}\n\n/**\n * Access a property or index on an object or array.\n *\n * @param obj The object or array to access.\n * @param segment The property key or array index.\n * @returns The accessed value or undefined if not accessible.\n */\nfunction accessProperty(obj: unknown, segment: string | number): unknown {\n if (typeof segment === \"string\") {\n return getOwnProperty(obj, segment);\n }\n\n // Numeric index for arrays\n if (Array.isArray(obj) && segment >= 0 && segment < obj.length) {\n return obj[segment];\n }\n\n return undefined;\n}\n\n/**\n * Resolve a nested property path from an object.\n *\n * There are two types of property access patterns:\n * 1. Array/index access: [0] or [\"prop\"]\n * 2. Property access: prop or prop?.next\n *\n * @param obj The object to traverse.\n * @param path The property path (e.g., \"user.name\", \"users[0].email\", \"user['full-name']\").\n * @returns The resolved value or undefined if path doesn't exist.\n */\nfunction resolvePropertyPath(obj: unknown, path: string): unknown {\n if (obj == null) return undefined;\n\n // Check for invalid paths\n if (path.length === 0 || path.endsWith(\".\")) return undefined;\n\n let current: unknown = obj;\n let i = 0;\n const len = path.length;\n\n while (i < len) {\n // Handle optional chaining\n const isOptional = path.slice(i, i + 2) === \"?.\";\n if (isOptional) {\n i += 2;\n if (current == null) return undefined;\n } else if (current == null) {\n return undefined;\n }\n\n // Parse the next segment\n const result = parseNextSegment(path, i);\n if (result === null) return undefined;\n\n const { segment, nextIndex } = result;\n i = nextIndex;\n\n // Access the property/index\n current = accessProperty(current, segment);\n if (current === undefined) {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Parse a message template into a message template array and a values array.\n *\n * Placeholders to be replaced with `values` are indicated by keys in curly braces\n * (e.g., `{value}`). The system supports both simple property access and nested\n * property access patterns:\n *\n * **Simple property access:**\n * ```ts\n * parseMessageTemplate(\"Hello, {user}!\", { user: \"foo\" })\n * // Returns: [\"Hello, \", \"foo\", \"!\"]\n * ```\n *\n * **Nested property access (dot notation):**\n * ```ts\n * parseMessageTemplate(\"Hello, {user.name}!\", {\n * user: { name: \"foo\", email: \"foo@example.com\" }\n * })\n * // Returns: [\"Hello, \", \"foo\", \"!\"]\n * ```\n *\n * **Array indexing:**\n * ```ts\n * parseMessageTemplate(\"First: {users[0]}\", {\n * users: [\"foo\", \"bar\", \"baz\"]\n * })\n * // Returns: [\"First: \", \"foo\", \"\"]\n * ```\n *\n * **Bracket notation for special property names:**\n * ```ts\n * parseMessageTemplate(\"Name: {user[\\\"full-name\\\"]}\", {\n * user: { \"full-name\": \"foo bar\" }\n * })\n * // Returns: [\"Name: \", \"foo bar\", \"\"]\n * ```\n *\n * **Optional chaining for safe navigation:**\n * ```ts\n * parseMessageTemplate(\"Email: {user?.profile?.email}\", {\n * user: { name: \"foo\" }\n * })\n * // Returns: [\"Email: \", undefined, \"\"]\n * ```\n *\n * **Wildcard patterns:**\n * - `{*}` - Replaced with the entire properties object\n * - `{ key-with-whitespace }` - Whitespace is trimmed when looking up keys\n *\n * **Escaping:**\n * - `{{` and `}}` are escaped literal braces\n *\n * **Error handling:**\n * - Non-existent paths return `undefined`\n * - Malformed expressions resolve to `undefined` without throwing errors\n * - Out of bounds array access returns `undefined`\n *\n * @param template The message template string containing placeholders.\n * @param properties The values to replace placeholders with.\n * @returns The message template array with values interleaved between text segments.\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 // If property not found directly and this looks like nested access, try nested resolution\n if (prop === undefined && isNestedAccess(trimmedKey)) {\n prop = resolvePropertyPath(properties, trimmedKey);\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,aAA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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;QACC;AAEL,QAAI,QAAQ,WAEV,QAAO,OAAO,aAAa,WAAW,OAAO,WAAW;QAGxD,QAAO,WAAW;AAIpB,QAAI,mBAAsB,eAAe,WAAW,CAClD,QAAO,oBAAoB,YAAY,WAAW;GAErD;AAED,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"}
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>","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\">","key: string","obj: unknown","path: string","fromIndex: number","segment: string | number","current: unknown","template: string","message: unknown[]","prop: unknown","template: TemplateStringsArray","values: readonly unknown[]"],"sources":["../src/logger.ts"],"sourcesContent":["import {\n type ContextLocalStorage,\n getCategoryPrefix,\n getImplicitContext,\n} 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 categoryPrefix = getCategoryPrefix();\n const baseCategory = \"category\" in record\n ? (record as LogRecord).category\n : this.category;\n const fullCategory = categoryPrefix.length > 0\n ? [...categoryPrefix, ...baseCategory]\n : baseCategory;\n\n // Create the full record by copying property descriptors from the original\n // record, which preserves getters without invoking them (unlike spread).\n const descriptors = Object.getOwnPropertyDescriptors(record) as\n & PropertyDescriptorMap\n & { category?: PropertyDescriptor };\n descriptors.category = {\n value: fullCategory,\n enumerable: true,\n configurable: true,\n };\n const fullRecord = Object.defineProperties({}, descriptors) as LogRecord;\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 = getImplicitContext();\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 = getImplicitContext();\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 = getImplicitContext();\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 * Check if a property access key contains nested access patterns.\n * @param key The property key to check.\n * @returns True if the key contains nested access patterns.\n */\nfunction isNestedAccess(key: string): boolean {\n return key.includes(\".\") || key.includes(\"[\") || key.includes(\"?.\");\n}\n\n/**\n * Safely access an own property from an object, blocking prototype pollution.\n *\n * @param obj The object to access the property from.\n * @param key The property key to access.\n * @returns The property value or undefined if not accessible.\n */\nfunction getOwnProperty(obj: unknown, key: string): unknown {\n // Block dangerous prototype keys\n if (key === \"__proto__\" || key === \"prototype\" || key === \"constructor\") {\n return undefined;\n }\n\n if ((typeof obj === \"object\" || typeof obj === \"function\") && obj !== null) {\n return Object.prototype.hasOwnProperty.call(obj, key)\n ? (obj as Record<string, unknown>)[key]\n : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Result of parsing a single segment from a property path.\n */\ninterface ParseSegmentResult {\n segment: string | number;\n nextIndex: number;\n}\n\n/**\n * Parse the next segment from a property path string.\n *\n * @param path The full property path string.\n * @param fromIndex The index to start parsing from.\n * @returns The parsed segment and next index, or null if parsing fails.\n */\nfunction parseNextSegment(\n path: string,\n fromIndex: number,\n): ParseSegmentResult | null {\n const len = path.length;\n let i = fromIndex;\n\n if (i >= len) return null;\n\n let segment: string | number;\n\n if (path[i] === \"[\") {\n // Bracket notation: [0] or [\"prop\"]\n i++;\n if (i >= len) return null;\n\n if (path[i] === '\"' || path[i] === \"'\") {\n // Quoted property name: [\"prop-name\"]\n const quote = path[i];\n i++;\n // Build segment with proper escape handling\n let segmentStr = \"\";\n while (i < len && path[i] !== quote) {\n if (path[i] === \"\\\\\") {\n i++; // Skip backslash\n if (i < len) {\n // Handle escape sequences according to JavaScript spec\n const escapeChar = path[i];\n switch (escapeChar) {\n case \"n\":\n segmentStr += \"\\n\";\n break;\n case \"t\":\n segmentStr += \"\\t\";\n break;\n case \"r\":\n segmentStr += \"\\r\";\n break;\n case \"b\":\n segmentStr += \"\\b\";\n break;\n case \"f\":\n segmentStr += \"\\f\";\n break;\n case \"v\":\n segmentStr += \"\\v\";\n break;\n case \"0\":\n segmentStr += \"\\0\";\n break;\n case \"\\\\\":\n segmentStr += \"\\\\\";\n break;\n case '\"':\n segmentStr += '\"';\n break;\n case \"'\":\n segmentStr += \"'\";\n break;\n case \"u\":\n // Unicode escape: \\uXXXX\n if (i + 4 < len) {\n const hex = path.slice(i + 1, i + 5);\n const codePoint = Number.parseInt(hex, 16);\n if (!Number.isNaN(codePoint)) {\n segmentStr += String.fromCharCode(codePoint);\n i += 4; // Skip the 4 hex digits\n } else {\n // Invalid unicode escape, keep as-is\n segmentStr += escapeChar;\n }\n } else {\n // Not enough characters for unicode escape\n segmentStr += escapeChar;\n }\n break;\n default:\n // For any other character after \\, just add it as-is\n segmentStr += escapeChar;\n }\n i++;\n }\n } else {\n segmentStr += path[i];\n i++;\n }\n }\n if (i >= len) return null;\n segment = segmentStr;\n i++; // Skip closing quote\n } else {\n // Array index: [0]\n const startIndex = i;\n while (\n i < len && path[i] !== \"]\" && path[i] !== \"'\" && path[i] !== '\"'\n ) {\n i++;\n }\n if (i >= len) return null;\n const indexStr = path.slice(startIndex, i);\n // Empty bracket is invalid\n if (indexStr.length === 0) return null;\n const indexNum = Number(indexStr);\n segment = Number.isNaN(indexNum) ? indexStr : indexNum;\n }\n\n // Skip closing bracket\n while (i < len && path[i] !== \"]\") i++;\n if (i < len) i++;\n } else {\n // Dot notation: prop\n const startIndex = i;\n while (\n i < len && path[i] !== \".\" && path[i] !== \"[\" && path[i] !== \"?\" &&\n path[i] !== \"]\"\n ) {\n i++;\n }\n segment = path.slice(startIndex, i);\n // Empty segment is invalid (e.g., leading dot, double dot, trailing dot)\n if (segment.length === 0) return null;\n }\n\n // Skip dot separator\n if (i < len && path[i] === \".\") i++;\n\n return { segment, nextIndex: i };\n}\n\n/**\n * Access a property or index on an object or array.\n *\n * @param obj The object or array to access.\n * @param segment The property key or array index.\n * @returns The accessed value or undefined if not accessible.\n */\nfunction accessProperty(obj: unknown, segment: string | number): unknown {\n if (typeof segment === \"string\") {\n return getOwnProperty(obj, segment);\n }\n\n // Numeric index for arrays\n if (Array.isArray(obj) && segment >= 0 && segment < obj.length) {\n return obj[segment];\n }\n\n return undefined;\n}\n\n/**\n * Resolve a nested property path from an object.\n *\n * There are two types of property access patterns:\n * 1. Array/index access: [0] or [\"prop\"]\n * 2. Property access: prop or prop?.next\n *\n * @param obj The object to traverse.\n * @param path The property path (e.g., \"user.name\", \"users[0].email\", \"user['full-name']\").\n * @returns The resolved value or undefined if path doesn't exist.\n */\nfunction resolvePropertyPath(obj: unknown, path: string): unknown {\n if (obj == null) return undefined;\n\n // Check for invalid paths\n if (path.length === 0 || path.endsWith(\".\")) return undefined;\n\n let current: unknown = obj;\n let i = 0;\n const len = path.length;\n\n while (i < len) {\n // Handle optional chaining\n const isOptional = path.slice(i, i + 2) === \"?.\";\n if (isOptional) {\n i += 2;\n if (current == null) return undefined;\n } else if (current == null) {\n return undefined;\n }\n\n // Parse the next segment\n const result = parseNextSegment(path, i);\n if (result === null) return undefined;\n\n const { segment, nextIndex } = result;\n i = nextIndex;\n\n // Access the property/index\n current = accessProperty(current, segment);\n if (current === undefined) {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Parse a message template into a message template array and a values array.\n *\n * Placeholders to be replaced with `values` are indicated by keys in curly braces\n * (e.g., `{value}`). The system supports both simple property access and nested\n * property access patterns:\n *\n * **Simple property access:**\n * ```ts\n * parseMessageTemplate(\"Hello, {user}!\", { user: \"foo\" })\n * // Returns: [\"Hello, \", \"foo\", \"!\"]\n * ```\n *\n * **Nested property access (dot notation):**\n * ```ts\n * parseMessageTemplate(\"Hello, {user.name}!\", {\n * user: { name: \"foo\", email: \"foo@example.com\" }\n * })\n * // Returns: [\"Hello, \", \"foo\", \"!\"]\n * ```\n *\n * **Array indexing:**\n * ```ts\n * parseMessageTemplate(\"First: {users[0]}\", {\n * users: [\"foo\", \"bar\", \"baz\"]\n * })\n * // Returns: [\"First: \", \"foo\", \"\"]\n * ```\n *\n * **Bracket notation for special property names:**\n * ```ts\n * parseMessageTemplate(\"Name: {user[\\\"full-name\\\"]}\", {\n * user: { \"full-name\": \"foo bar\" }\n * })\n * // Returns: [\"Name: \", \"foo bar\", \"\"]\n * ```\n *\n * **Optional chaining for safe navigation:**\n * ```ts\n * parseMessageTemplate(\"Email: {user?.profile?.email}\", {\n * user: { name: \"foo\" }\n * })\n * // Returns: [\"Email: \", undefined, \"\"]\n * ```\n *\n * **Wildcard patterns:**\n * - `{*}` - Replaced with the entire properties object\n * - `{ key-with-whitespace }` - Whitespace is trimmed when looking up keys\n *\n * **Escaping:**\n * - `{{` and `}}` are escaped literal braces\n *\n * **Error handling:**\n * - Non-existent paths return `undefined`\n * - Malformed expressions resolve to `undefined` without throwing errors\n * - Out of bounds array access returns `undefined`\n *\n * @param template The message template string containing placeholders.\n * @param properties The values to replace placeholders with.\n * @returns The message template array with values interleaved between text segments.\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 // If property not found directly and this looks like nested access, try nested resolution\n if (prop === undefined && isNestedAccess(trimmedKey)) {\n prop = resolvePropertyPath(properties, trimmedKey);\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":";;;;;;;;;;;;;;;;AAgyBA,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,WA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AAK,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;QACC;AAEL,QAAI,QAAQ,WAEV,QAAO,OAAO,aAAa,WAAW,OAAO,WAAW;QAGxD,QAAO,WAAW;AAIpB,QAAI,mBAAsB,eAAe,WAAW,CAClD,QAAO,oBAAoB,YAAY,WAAW;GAErD;AAED,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/dist/mod.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  const require_filter = require('./filter.cjs');
2
+ const require_context = require('./context.cjs');
2
3
  const require_level = require('./level.cjs');
3
4
  const require_logger = require('./logger.cjs');
4
5
  const require_formatter = require('./formatter.cjs');
5
6
  const require_sink = require('./sink.cjs');
6
7
  const require_config = require('./config.cjs');
7
- const require_context = require('./context.cjs');
8
8
 
9
9
  exports.ConfigError = require_config.ConfigError;
10
10
  exports.ansiColorFormatter = require_formatter.ansiColorFormatter;
@@ -32,5 +32,6 @@ exports.parseLogLevel = require_level.parseLogLevel;
32
32
  exports.reset = require_config.reset;
33
33
  exports.resetSync = require_config.resetSync;
34
34
  exports.toFilter = require_filter.toFilter;
35
+ exports.withCategoryPrefix = require_context.withCategoryPrefix;
35
36
  exports.withContext = require_context.withContext;
36
37
  exports.withFilter = require_sink.withFilter;
package/dist/mod.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextLocalStorage, withContext } from "./context.cjs";
1
+ import { ContextLocalStorage, withCategoryPrefix, withContext } from "./context.cjs";
2
2
  import { LogLevel, compareLogLevel, getLogLevels, isLogLevel, parseLogLevel } from "./level.cjs";
3
3
  import { LogRecord } from "./record.cjs";
4
4
  import { Filter, FilterLike, getLevelFilter, toFilter } from "./filter.cjs";
@@ -6,4 +6,4 @@ import { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, ConsoleFormatter, Form
6
6
  import { AsyncSink, ConsoleSinkOptions, FingersCrossedOptions, Sink, StreamSinkOptions, fingersCrossed, fromAsyncSink, getConsoleSink, getStreamSink, withFilter } from "./sink.cjs";
7
7
  import { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync } from "./config.cjs";
8
8
  import { LogMethod, Logger, getLogger } from "./logger.cjs";
9
- export { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, AsyncSink, Config, ConfigError, ConsoleFormatter, ConsoleSinkOptions, ContextLocalStorage, Filter, FilterLike, FingersCrossedOptions, FormattedValues, JsonLinesFormatterOptions, LogLevel, LogMethod, LogRecord, Logger, LoggerConfig, Sink, StreamSinkOptions, TextFormatter, TextFormatterOptions, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withContext, withFilter };
9
+ export { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, AsyncSink, Config, ConfigError, ConsoleFormatter, ConsoleSinkOptions, ContextLocalStorage, Filter, FilterLike, FingersCrossedOptions, FormattedValues, JsonLinesFormatterOptions, LogLevel, LogMethod, LogRecord, Logger, LoggerConfig, Sink, StreamSinkOptions, TextFormatter, TextFormatterOptions, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withCategoryPrefix, withContext, withFilter };
package/dist/mod.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextLocalStorage, withContext } from "./context.js";
1
+ import { ContextLocalStorage, withCategoryPrefix, withContext } from "./context.js";
2
2
  import { LogLevel, compareLogLevel, getLogLevels, isLogLevel, parseLogLevel } from "./level.js";
3
3
  import { LogRecord } from "./record.js";
4
4
  import { Filter, FilterLike, getLevelFilter, toFilter } from "./filter.js";
@@ -6,4 +6,4 @@ import { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, ConsoleFormatter, Form
6
6
  import { AsyncSink, ConsoleSinkOptions, FingersCrossedOptions, Sink, StreamSinkOptions, fingersCrossed, fromAsyncSink, getConsoleSink, getStreamSink, withFilter } from "./sink.js";
7
7
  import { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync } from "./config.js";
8
8
  import { LogMethod, Logger, getLogger } from "./logger.js";
9
- export { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, AsyncSink, Config, ConfigError, ConsoleFormatter, ConsoleSinkOptions, ContextLocalStorage, Filter, FilterLike, FingersCrossedOptions, FormattedValues, JsonLinesFormatterOptions, LogLevel, LogMethod, LogRecord, Logger, LoggerConfig, Sink, StreamSinkOptions, TextFormatter, TextFormatterOptions, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withContext, withFilter };
9
+ export { AnsiColor, AnsiColorFormatterOptions, AnsiStyle, AsyncSink, Config, ConfigError, ConsoleFormatter, ConsoleSinkOptions, ContextLocalStorage, Filter, FilterLike, FingersCrossedOptions, FormattedValues, JsonLinesFormatterOptions, LogLevel, LogMethod, LogRecord, Logger, LoggerConfig, Sink, StreamSinkOptions, TextFormatter, TextFormatterOptions, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withCategoryPrefix, withContext, withFilter };
package/dist/mod.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { getLevelFilter, toFilter } from "./filter.js";
2
+ import { withCategoryPrefix, withContext } from "./context.js";
2
3
  import { compareLogLevel, getLogLevels, isLogLevel, parseLogLevel } from "./level.js";
3
4
  import { getLogger } from "./logger.js";
4
5
  import { ansiColorFormatter, defaultConsoleFormatter, defaultTextFormatter, getAnsiColorFormatter, getJsonLinesFormatter, getTextFormatter, jsonLinesFormatter } from "./formatter.js";
5
6
  import { fingersCrossed, fromAsyncSink, getConsoleSink, getStreamSink, withFilter } from "./sink.js";
6
7
  import { ConfigError, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync } from "./config.js";
7
- import { withContext } from "./context.js";
8
8
 
9
- export { ConfigError, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withContext, withFilter };
9
+ export { ConfigError, ansiColorFormatter, compareLogLevel, configure, configureSync, defaultConsoleFormatter, defaultTextFormatter, dispose, disposeSync, fingersCrossed, fromAsyncSink, getAnsiColorFormatter, getConfig, getConsoleSink, getJsonLinesFormatter, getLevelFilter, getLogLevels, getLogger, getStreamSink, getTextFormatter, isLogLevel, jsonLinesFormatter, parseLogLevel, reset, resetSync, toFilter, withCategoryPrefix, withContext, withFilter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.3.0-dev.376+3abddd8c",
3
+ "version": "1.3.0-dev.378+36427b63",
4
4
  "description": "Simple logging library with zero dependencies for Deno/Node.js/Bun/browsers",
5
5
  "keywords": [
6
6
  "logging",
@@ -3,7 +3,7 @@ import { assertEquals } from "@std/assert/equals";
3
3
  import { delay } from "@std/async/delay";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { configure, reset } from "./config.ts";
6
- import { withContext } from "./context.ts";
6
+ import { withCategoryPrefix, withContext } from "./context.ts";
7
7
  import { getLogger } from "./logger.ts";
8
8
  import type { LogRecord } from "./record.ts";
9
9
 
@@ -185,3 +185,157 @@ test("withContext()", async () => {
185
185
  await reset();
186
186
  }
187
187
  });
188
+
189
+ test("withCategoryPrefix()", async () => {
190
+ const buffer: LogRecord[] = [];
191
+
192
+ { // set up
193
+ await configure({
194
+ sinks: {
195
+ buffer: buffer.push.bind(buffer),
196
+ },
197
+ loggers: [
198
+ { category: [], sinks: ["buffer"], lowestLevel: "debug" },
199
+ { category: ["logtape", "meta"], sinks: [], lowestLevel: "warning" },
200
+ ],
201
+ contextLocalStorage: new AsyncLocalStorage(),
202
+ reset: true,
203
+ });
204
+ }
205
+
206
+ try {
207
+ // basic prefix with array
208
+ getLogger(["core-lib"]).debug("without prefix");
209
+ assertEquals(buffer[0].category, ["core-lib"]);
210
+ buffer.pop();
211
+
212
+ const rv = withCategoryPrefix(["sdk-1"], () => {
213
+ getLogger(["core-lib"]).debug("with prefix");
214
+ return 123;
215
+ });
216
+ assertEquals(rv, 123);
217
+ assertEquals(buffer[0].category, ["sdk-1", "core-lib"]);
218
+ buffer.pop();
219
+
220
+ // prefix should not persist after callback
221
+ getLogger(["core-lib"]).debug("after prefix");
222
+ assertEquals(buffer[0].category, ["core-lib"]);
223
+ buffer.pop();
224
+
225
+ // basic prefix with string
226
+ withCategoryPrefix("sdk-2", () => {
227
+ getLogger(["core-lib"]).debug("string prefix");
228
+ });
229
+ assertEquals(buffer[0].category, ["sdk-2", "core-lib"]);
230
+ buffer.pop();
231
+
232
+ // nesting prefixes
233
+ withCategoryPrefix(["app"], () => {
234
+ withCategoryPrefix(["sdk-1"], () => {
235
+ getLogger(["core-lib"]).debug("nested");
236
+ });
237
+ });
238
+ assertEquals(buffer[0].category, ["app", "sdk-1", "core-lib"]);
239
+ buffer.pop();
240
+
241
+ // combining with withContext
242
+ withCategoryPrefix(["my-sdk"], () => {
243
+ withContext({ requestId: "abc-123" }, () => {
244
+ getLogger(["internal"]).debug("combined");
245
+ });
246
+ });
247
+ assertEquals(buffer[0].category, ["my-sdk", "internal"]);
248
+ assertEquals(buffer[0].properties, { requestId: "abc-123" });
249
+ buffer.pop();
250
+
251
+ // withContext inside withCategoryPrefix
252
+ withContext({ userId: 42 }, () => {
253
+ withCategoryPrefix(["sdk"], () => {
254
+ getLogger(["lib"]).debug("context then prefix");
255
+ });
256
+ });
257
+ assertEquals(buffer[0].category, ["sdk", "lib"]);
258
+ assertEquals(buffer[0].properties, { userId: 42 });
259
+ buffer.pop();
260
+
261
+ // concurrent runs - each should have isolated prefix
262
+ await Promise.all([
263
+ (async () => {
264
+ await delay(Math.random() * 100);
265
+ withCategoryPrefix(["sdk-a"], () => {
266
+ getLogger(["lib"]).debug("a");
267
+ });
268
+ })(),
269
+ (async () => {
270
+ await delay(Math.random() * 100);
271
+ withCategoryPrefix(["sdk-b"], () => {
272
+ getLogger(["lib"]).debug("b");
273
+ });
274
+ })(),
275
+ (async () => {
276
+ await delay(Math.random() * 100);
277
+ withCategoryPrefix(["sdk-c"], () => {
278
+ getLogger(["lib"]).debug("c");
279
+ });
280
+ })(),
281
+ (async () => {
282
+ await delay(Math.random() * 100);
283
+ withCategoryPrefix(["sdk-d"], () => {
284
+ getLogger(["lib"]).debug("d");
285
+ });
286
+ })(),
287
+ ]);
288
+ assertEquals(buffer.length, 4);
289
+ for (const log of buffer) {
290
+ if (log.message[0] === "a") {
291
+ assertEquals(log.category, ["sdk-a", "lib"]);
292
+ } else if (log.message[0] === "b") {
293
+ assertEquals(log.category, ["sdk-b", "lib"]);
294
+ } else if (log.message[0] === "c") {
295
+ assertEquals(log.category, ["sdk-c", "lib"]);
296
+ } else {
297
+ assertEquals(log.category, ["sdk-d", "lib"]);
298
+ }
299
+ }
300
+ } finally {
301
+ await reset();
302
+ }
303
+
304
+ // without contextLocalStorage configured
305
+ const metaBuffer: LogRecord[] = [];
306
+
307
+ { // set up
308
+ await configure({
309
+ sinks: {
310
+ buffer: buffer.push.bind(buffer),
311
+ metaBuffer: metaBuffer.push.bind(metaBuffer),
312
+ },
313
+ loggers: [
314
+ { category: "my-app", sinks: ["buffer"], lowestLevel: "debug" },
315
+ {
316
+ category: ["logtape", "meta"],
317
+ sinks: ["metaBuffer"],
318
+ lowestLevel: "warning",
319
+ },
320
+ ],
321
+ reset: true,
322
+ });
323
+ }
324
+
325
+ try {
326
+ while (buffer.length > 0) buffer.pop();
327
+ const rv = withCategoryPrefix(["sdk-1"], () => {
328
+ getLogger(["my-app"]).debug("no storage");
329
+ return 456;
330
+ });
331
+ assertEquals(rv, 456);
332
+ // Without storage, category should not have prefix
333
+ assertEquals(buffer[0].category, ["my-app"]);
334
+ // Warning should be logged to meta logger
335
+ assertEquals(metaBuffer.length, 1);
336
+ assertEquals(metaBuffer[0].category, ["logtape", "meta"]);
337
+ assertEquals(metaBuffer[0].level, "warning");
338
+ } finally {
339
+ await reset();
340
+ }
341
+ });
package/src/context.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import { LoggerImpl } from "./logger.ts";
2
2
 
3
+ /**
4
+ * Internal symbol for storing category prefix in context.
5
+ */
6
+ const categoryPrefixSymbol: unique symbol = Symbol.for(
7
+ "logtape.categoryPrefix",
8
+ ) as typeof categoryPrefixSymbol;
9
+
3
10
  /**
4
11
  * A generic interface for a context-local storage. It resembles
5
12
  * the {@link AsyncLocalStorage} API from Node.js.
@@ -53,3 +60,91 @@ export function withContext<T>(
53
60
  callback,
54
61
  );
55
62
  }
63
+
64
+ /**
65
+ * Gets the current category prefix from context local storage.
66
+ * @returns The current category prefix, or an empty array if not set.
67
+ * @since 1.3.0
68
+ */
69
+ export function getCategoryPrefix(): readonly string[] {
70
+ const rootLogger = LoggerImpl.getLogger();
71
+ const store = rootLogger.contextLocalStorage?.getStore();
72
+ if (store == null) return [];
73
+ const prefix = store[categoryPrefixSymbol as unknown as string];
74
+ return Array.isArray(prefix) ? prefix : [];
75
+ }
76
+
77
+ /**
78
+ * Gets the current implicit context from context local storage, excluding
79
+ * internal symbol keys (like category prefix).
80
+ * @returns The current implicit context without internal symbol keys.
81
+ * @since 1.3.0
82
+ */
83
+ export function getImplicitContext(): Record<string, unknown> {
84
+ const rootLogger = LoggerImpl.getLogger();
85
+ const store = rootLogger.contextLocalStorage?.getStore();
86
+ if (store == null) return {};
87
+ // Filter out symbol keys (like categoryPrefixSymbol)
88
+ const result: Record<string, unknown> = {};
89
+ for (const key of Object.keys(store)) {
90
+ result[key] = store[key];
91
+ }
92
+ return result;
93
+ }
94
+
95
+ /**
96
+ * Runs a callback with the given category prefix prepended to all log
97
+ * categories within the callback context.
98
+ *
99
+ * This is useful for SDKs or libraries that want to add their own category
100
+ * as a prefix to logs from their internal dependencies.
101
+ *
102
+ * If no `contextLocalStorage` is configured, this function does nothing and
103
+ * just returns the return value of the callback. It also logs a warning to
104
+ * the `["logtape", "meta"]` logger in this case.
105
+ *
106
+ * @example Basic usage
107
+ * ```typescript
108
+ * import { getLogger, withCategoryPrefix } from "@logtape/logtape";
109
+ *
110
+ * export function sdkFunction() {
111
+ * return withCategoryPrefix(["my-sdk"], () => {
112
+ * // Any logs from internal libraries within this context
113
+ * // will have ["my-sdk"] prepended to their category
114
+ * return internalLibraryFunction();
115
+ * });
116
+ * }
117
+ * ```
118
+ *
119
+ * @param prefix The category prefix to prepend. Can be a string or an array
120
+ * of strings.
121
+ * @param callback The callback to run.
122
+ * @returns The return value of the callback.
123
+ * @since 1.3.0
124
+ */
125
+ export function withCategoryPrefix<T>(
126
+ prefix: string | readonly string[],
127
+ callback: () => T,
128
+ ): T {
129
+ const rootLogger = LoggerImpl.getLogger();
130
+ if (rootLogger.contextLocalStorage == null) {
131
+ LoggerImpl.getLogger(["logtape", "meta"]).warn(
132
+ "Context-local storage is not configured. " +
133
+ "Specify contextLocalStorage option in the configure() function.",
134
+ );
135
+ return callback();
136
+ }
137
+ const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
138
+ const parentPrefix = getCategoryPrefix();
139
+ const newPrefix = typeof prefix === "string" ? [prefix] : [...prefix];
140
+ return rootLogger.contextLocalStorage.run(
141
+ {
142
+ ...parentContext,
143
+ [categoryPrefixSymbol as unknown as string]: [
144
+ ...parentPrefix,
145
+ ...newPrefix,
146
+ ],
147
+ },
148
+ callback,
149
+ );
150
+ }
package/src/logger.ts CHANGED
@@ -1,4 +1,8 @@
1
- import type { ContextLocalStorage } from "./context.ts";
1
+ import {
2
+ type ContextLocalStorage,
3
+ getCategoryPrefix,
4
+ getImplicitContext,
5
+ } from "./context.ts";
2
6
  import type { Filter } from "./filter.ts";
3
7
  import { compareLogLevel, type LogLevel } from "./level.ts";
4
8
  import type { LogRecord } from "./record.ts";
@@ -924,9 +928,25 @@ export class LoggerImpl implements Logger {
924
928
  record: Omit<LogRecord, "category"> | LogRecord,
925
929
  bypassSinks?: Set<Sink>,
926
930
  ): void {
927
- const fullRecord: LogRecord = "category" in record
928
- ? record as LogRecord
929
- : { ...record, category: this.category };
931
+ const categoryPrefix = getCategoryPrefix();
932
+ const baseCategory = "category" in record
933
+ ? (record as LogRecord).category
934
+ : this.category;
935
+ const fullCategory = categoryPrefix.length > 0
936
+ ? [...categoryPrefix, ...baseCategory]
937
+ : baseCategory;
938
+
939
+ // Create the full record by copying property descriptors from the original
940
+ // record, which preserves getters without invoking them (unlike spread).
941
+ const descriptors = Object.getOwnPropertyDescriptors(record) as
942
+ & PropertyDescriptorMap
943
+ & { category?: PropertyDescriptor };
944
+ descriptors.category = {
945
+ value: fullCategory,
946
+ enumerable: true,
947
+ configurable: true,
948
+ };
949
+ const fullRecord = Object.defineProperties({}, descriptors) as LogRecord;
930
950
 
931
951
  if (
932
952
  this.lowestLevel === null ||
@@ -958,8 +978,7 @@ export class LoggerImpl implements Logger {
958
978
  properties: Record<string, unknown> | (() => Record<string, unknown>),
959
979
  bypassSinks?: Set<Sink>,
960
980
  ): void {
961
- const implicitContext =
962
- LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
981
+ const implicitContext = getImplicitContext();
963
982
  let cachedProps: Record<string, unknown> | undefined = undefined;
964
983
  const record: LogRecord = typeof properties === "function"
965
984
  ? {
@@ -999,8 +1018,7 @@ export class LoggerImpl implements Logger {
999
1018
  callback: LogCallback,
1000
1019
  properties: Record<string, unknown> = {},
1001
1020
  ): void {
1002
- const implicitContext =
1003
- LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
1021
+ const implicitContext = getImplicitContext();
1004
1022
  let rawMessage: TemplateStringsArray | undefined = undefined;
1005
1023
  let msg: unknown[] | undefined = undefined;
1006
1024
  function realizeMessage(): [unknown[], TemplateStringsArray] {
@@ -1033,8 +1051,7 @@ export class LoggerImpl implements Logger {
1033
1051
  values: unknown[],
1034
1052
  properties: Record<string, unknown> = {},
1035
1053
  ): void {
1036
- const implicitContext =
1037
- LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
1054
+ const implicitContext = getImplicitContext();
1038
1055
  this.emit({
1039
1056
  category: this.category,
1040
1057
  level,
package/src/mod.ts CHANGED
@@ -10,7 +10,11 @@ export {
10
10
  reset,
11
11
  resetSync,
12
12
  } from "./config.ts";
13
- export { type ContextLocalStorage, withContext } from "./context.ts";
13
+ export {
14
+ type ContextLocalStorage,
15
+ withCategoryPrefix,
16
+ withContext,
17
+ } from "./context.ts";
14
18
  export {
15
19
  type Filter,
16
20
  type FilterLike,