@easyweb/logging 1.0.0 → 1.0.2
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 +7 -0
- package/dist/logger.d.ts +13 -3
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +37 -2
- package/dist/logger.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,13 @@ log.info({ projectId }, "Project created");
|
|
|
32
32
|
pino merges the mixin UNDER the object the call site passed, so an explicit
|
|
33
33
|
field always wins over an ambient one.
|
|
34
34
|
|
|
35
|
+
**The mixin hands pino a COPY of the scope (1.0.2).** pino's default merge is
|
|
36
|
+
`Object.assign(mixinObject, mergeObject)`, and 1.0.1 returned the live store —
|
|
37
|
+
so every call's fields were written into the request's context and appeared on
|
|
38
|
+
every later line of that request, an `err` included. It also skips any key the
|
|
39
|
+
logger already binds, which is why a `getLogger(req)` line or a subscriber's
|
|
40
|
+
`child({ requestId, queue })` line now carries `requestId` once, not twice.
|
|
41
|
+
|
|
35
42
|
## Usage
|
|
36
43
|
|
|
37
44
|
```ts
|
package/dist/logger.d.ts
CHANGED
|
@@ -25,9 +25,11 @@ export interface ServiceLoggerOptions {
|
|
|
25
25
|
export interface ServiceLogger {
|
|
26
26
|
logger: pino.Logger;
|
|
27
27
|
/**
|
|
28
|
-
* Kept for the ~42 files that import it
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* Kept for the ~42 files that import it, and still a child logger: a line
|
|
29
|
+
* logged from `res.on("close")` or a socket callback runs OUTSIDE the request
|
|
30
|
+
* scope, and the bound `requestId` is the only one it carries. Inside the
|
|
31
|
+
* scope the mixin skips the key the child already binds, so the line carries
|
|
32
|
+
* it once rather than twice.
|
|
31
33
|
*/
|
|
32
34
|
getLogger: (req: Request) => pino.Logger;
|
|
33
35
|
}
|
|
@@ -39,6 +41,14 @@ export interface ServiceLogger {
|
|
|
39
41
|
* explicit field always wins over the ambient one. That is what lets every
|
|
40
42
|
* existing `log.info({ projectId }, "...")` gain a requestId without being
|
|
41
43
|
* touched.
|
|
44
|
+
*
|
|
45
|
+
* **The mixin returns a COPY of the scope, and 1.0.1's did not.** pino's
|
|
46
|
+
* default merge is `Object.assign(mixinObject, mergeObject)`, so returning the
|
|
47
|
+
* live store wrote every call's fields INTO the request's context — and every
|
|
48
|
+
* later line in that request carried them. A production build's "Initial build
|
|
49
|
+
* failed" line carried `path: "middleware.ts"`, `tool: "screenshot"`, a design
|
|
50
|
+
* retrieval's diagnostics and an `err` from a different call entirely. "An
|
|
51
|
+
* explicit field always wins" was true of one line and false of the next.
|
|
42
52
|
*/
|
|
43
53
|
export declare function createServiceLogger(options: ServiceLoggerOptions): ServiceLogger;
|
|
44
54
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;CAC1C;AAsBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CA4Df"}
|
package/dist/logger.js
CHANGED
|
@@ -9,6 +9,24 @@ const context_1 = require("./context");
|
|
|
9
9
|
const redact_1 = require("./redact");
|
|
10
10
|
const serialize_1 = require("./serialize");
|
|
11
11
|
const transport_1 = require("./transport");
|
|
12
|
+
/**
|
|
13
|
+
* The keys a logger already writes itself, per logger instance.
|
|
14
|
+
*
|
|
15
|
+
* pino writes a child's bindings as a pre-built string and appends the merged
|
|
16
|
+
* object after it without de-duplicating, so an ambient key a child also binds
|
|
17
|
+
* appeared twice on every line — `getLogger(req)` binding `requestId` inside a
|
|
18
|
+
* scope that carries it too. Cached because `bindings()` re-parses that string
|
|
19
|
+
* on every call, and a logger's bindings do not change after it is made.
|
|
20
|
+
*/
|
|
21
|
+
const boundKeys = new WeakMap();
|
|
22
|
+
function keysBoundBy(logger) {
|
|
23
|
+
let keys = boundKeys.get(logger);
|
|
24
|
+
if (!keys) {
|
|
25
|
+
keys = new Set(Object.keys(logger.bindings()));
|
|
26
|
+
boundKeys.set(logger, keys);
|
|
27
|
+
}
|
|
28
|
+
return keys;
|
|
29
|
+
}
|
|
12
30
|
/**
|
|
13
31
|
* Builds the service's root logger.
|
|
14
32
|
*
|
|
@@ -17,6 +35,14 @@ const transport_1 = require("./transport");
|
|
|
17
35
|
* explicit field always wins over the ambient one. That is what lets every
|
|
18
36
|
* existing `log.info({ projectId }, "...")` gain a requestId without being
|
|
19
37
|
* touched.
|
|
38
|
+
*
|
|
39
|
+
* **The mixin returns a COPY of the scope, and 1.0.1's did not.** pino's
|
|
40
|
+
* default merge is `Object.assign(mixinObject, mergeObject)`, so returning the
|
|
41
|
+
* live store wrote every call's fields INTO the request's context — and every
|
|
42
|
+
* later line in that request carried them. A production build's "Initial build
|
|
43
|
+
* failed" line carried `path: "middleware.ts"`, `tool: "screenshot"`, a design
|
|
44
|
+
* retrieval's diagnostics and an `err` from a different call entirely. "An
|
|
45
|
+
* explicit field always wins" was true of one line and false of the next.
|
|
20
46
|
*/
|
|
21
47
|
function createServiceLogger(options) {
|
|
22
48
|
const env = options.env ?? process.env.NODE_ENV ?? "development";
|
|
@@ -38,9 +64,18 @@ function createServiceLogger(options) {
|
|
|
38
64
|
* calls are overwhelmingly on error paths — the failure would swallow
|
|
39
65
|
* exactly the line somebody needed.
|
|
40
66
|
*/
|
|
41
|
-
mixin() {
|
|
67
|
+
mixin(_mergeObject, _level, instance) {
|
|
42
68
|
try {
|
|
43
|
-
|
|
69
|
+
const context = (0, context_1.getContext)();
|
|
70
|
+
if (!context)
|
|
71
|
+
return {};
|
|
72
|
+
const bound = keysBoundBy(instance);
|
|
73
|
+
const ambient = {};
|
|
74
|
+
for (const [key, value] of Object.entries(context)) {
|
|
75
|
+
if (!bound.has(key))
|
|
76
|
+
ambient[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return ambient;
|
|
44
79
|
}
|
|
45
80
|
catch {
|
|
46
81
|
return {};
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;AA+EA,kDA8DC;AA7ID,gDAAwB;AAExB,uCAAuC;AACvC,qCAAkC;AAClC,2CAA6C;AAC7C,2CAA2D;AAqC3D;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAG,IAAI,OAAO,EAAoC,CAAC;AAElE,SAAS,WAAW,CAAC,MAAmB;IACtC,IAAI,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC/C,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,mBAAmB,CACjC,OAA6B;IAE7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IACjE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAErD,sEAAsE;IACtE,sEAAsE;IACtE,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,SAAS,GAAG,IAAA,0BAAc,EAAC,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,IAAA,wBAAY,EAAC,GAAG,CAAC,CAAC,CAAC;IAEjF,MAAM,WAAW,GAAuB;QACtC,KAAK,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACpE,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e,EAAE,CAC9C,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAG,GAA8B,CAAC,SAAS,EAAE,CAAC,CAAC;IAEzE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyweb/logging",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Shared structured logging for Easyweb microservices: one pino configuration, request-scoped context over AsyncLocalStorage, an HTTP access log, and the redaction every service needs before its logs leave the pod",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|