@logtape/logtape 0.7.0 → 0.7.1
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/esm/context.js +6 -1
- package/package.json +1 -1
- package/script/context.js +6 -1
- package/types/context.d.ts +4 -0
- package/types/context.d.ts.map +1 -1
package/esm/context.js
CHANGED
|
@@ -2,6 +2,10 @@ import { LoggerImpl } from "./logger.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Runs a callback with the given implicit context. Every single log record
|
|
4
4
|
* in the callback will have the given context.
|
|
5
|
+
*
|
|
6
|
+
* If no `contextLocalStorage` is configured, this function does nothing and
|
|
7
|
+
* just returns the return value of the callback. It also logs a warning to
|
|
8
|
+
* the `["logtape", "meta"]` logger in this case.
|
|
5
9
|
* @param context The context to inject.
|
|
6
10
|
* @param callback The callback to run.
|
|
7
11
|
* @returns The return value of the callback.
|
|
@@ -10,8 +14,9 @@ import { LoggerImpl } from "./logger.js";
|
|
|
10
14
|
export function withContext(context, callback) {
|
|
11
15
|
const rootLogger = LoggerImpl.getLogger();
|
|
12
16
|
if (rootLogger.contextLocalStorage == null) {
|
|
13
|
-
|
|
17
|
+
LoggerImpl.getLogger(["logtape", "meta"]).warn("Context-local storage is not configured. " +
|
|
14
18
|
"Specify contextLocalStorage option in the configure() function.");
|
|
19
|
+
return callback();
|
|
15
20
|
}
|
|
16
21
|
const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
|
|
17
22
|
return rootLogger.contextLocalStorage.run({ ...parentContext, ...context }, callback);
|
package/package.json
CHANGED
package/script/context.js
CHANGED
|
@@ -5,6 +5,10 @@ const logger_js_1 = require("./logger.js");
|
|
|
5
5
|
/**
|
|
6
6
|
* Runs a callback with the given implicit context. Every single log record
|
|
7
7
|
* in the callback will have the given context.
|
|
8
|
+
*
|
|
9
|
+
* If no `contextLocalStorage` is configured, this function does nothing and
|
|
10
|
+
* just returns the return value of the callback. It also logs a warning to
|
|
11
|
+
* the `["logtape", "meta"]` logger in this case.
|
|
8
12
|
* @param context The context to inject.
|
|
9
13
|
* @param callback The callback to run.
|
|
10
14
|
* @returns The return value of the callback.
|
|
@@ -13,8 +17,9 @@ const logger_js_1 = require("./logger.js");
|
|
|
13
17
|
function withContext(context, callback) {
|
|
14
18
|
const rootLogger = logger_js_1.LoggerImpl.getLogger();
|
|
15
19
|
if (rootLogger.contextLocalStorage == null) {
|
|
16
|
-
|
|
20
|
+
logger_js_1.LoggerImpl.getLogger(["logtape", "meta"]).warn("Context-local storage is not configured. " +
|
|
17
21
|
"Specify contextLocalStorage option in the configure() function.");
|
|
22
|
+
return callback();
|
|
18
23
|
}
|
|
19
24
|
const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
|
|
20
25
|
return rootLogger.contextLocalStorage.run({ ...parentContext, ...context }, callback);
|
package/types/context.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export interface ContextLocalStorage<T> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Runs a callback with the given implicit context. Every single log record
|
|
24
24
|
* in the callback will have the given context.
|
|
25
|
+
*
|
|
26
|
+
* If no `contextLocalStorage` is configured, this function does nothing and
|
|
27
|
+
* just returns the return value of the callback. It also logs a warning to
|
|
28
|
+
* the `["logtape", "meta"]` logger in this case.
|
|
25
29
|
* @param context The context to inject.
|
|
26
30
|
* @param callback The callback to run.
|
|
27
31
|
* @returns The return value of the callback.
|
package/types/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAEvC;;;;OAIG;IACH,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;CAC3B;AAED
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAEvC;;;;OAIG;IACH,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,MAAM,CAAC,GAChB,CAAC,CAcH"}
|