@webpieces/bunyan 0.3.383 → 0.3.385
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/package.json +3 -3
- package/src/BunyanLogger.js +5 -3
- package/src/BunyanLogger.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/bunyan",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.385",
|
|
4
4
|
"description": "Node-only bunyan LoggerFactory backends for webpieces: Console (local pretty) + GCP (@google-cloud/logging-bunyan), auto-enriched with HeaderRegistry context keys",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/core-util": "0.3.
|
|
27
|
-
"@webpieces/core-context": "0.3.
|
|
26
|
+
"@webpieces/core-util": "0.3.385",
|
|
27
|
+
"@webpieces/core-context": "0.3.385",
|
|
28
28
|
"bunyan": "1.8.15",
|
|
29
29
|
"@google-cloud/logging-bunyan": "5.1.0",
|
|
30
30
|
"@types/bunyan": "1.8.11"
|
package/src/BunyanLogger.js
CHANGED
|
@@ -65,9 +65,11 @@ class BunyanLogger {
|
|
|
65
65
|
this.reportMissingContextOnce();
|
|
66
66
|
return fields;
|
|
67
67
|
}
|
|
68
|
-
// ONE loop, in HeaderRegistry.
|
|
69
|
-
// ContextKey masks its own value.
|
|
70
|
-
|
|
68
|
+
// ONE loop, in HeaderRegistry.buildStructuredLogFields — the registry owns the keys and each
|
|
69
|
+
// ContextKey masks its own value. Values may be OBJECTS (the `api` tag), so an object-valued key
|
|
70
|
+
// nests into the structured payload (bunyan's GCP stream serializes fields) rather than being
|
|
71
|
+
// dropped by the string-only buildLogFields.
|
|
72
|
+
core_context_1.RequestContext.buildStructuredLogFields().forEach((value, name) => {
|
|
71
73
|
fields[name] = value;
|
|
72
74
|
});
|
|
73
75
|
if (err) {
|
package/src/BunyanLogger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunyanLogger.js","sourceRoot":"","sources":["../../../../../packages/logging/bunyan/src/BunyanLogger.ts"],"names":[],"mappings":";;;AAEA,0DAAyD;AACzD,+CAA4C;AAE5C,+EAA+E;AAC/E,4DAA4D;AAC5D,MAAM,uBAAuB,GACzB,iFAAiF;IACjF,0FAA0F;IAC1F,4FAA4F,CAAC;AAEjG,8EAA8E;AAC9E,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC,SAAS,aAAa,CAAC,KAAyB,EAAE,QAAQ,GAAG,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,cAAc,CAAC,GAAU;IAC9B,MAAM,IAAI,GAAG,IAAI,yBAAW,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IAC/D,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,IAAI,kBAAkB,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,yBAAW,CAClB,mBAAmB,GAAG,CAAC,IAAI,EAAE,EAC7B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAC7B,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAC9B,CAAC;AACN,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,YAAY;IAK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,CAAC,uBAAuB,CAAC,CAAC;IAC/C,CAAC;CACJ;AAxDD,oCAwDC","sourcesContent":["import type Logger from 'bunyan';\nimport type { Logger as WpLogger } from '@webpieces/core-util';\nimport { RequestContext } from '@webpieces/core-context';\nimport { LoggedError } from './LoggedError';\n\n// A log line with no active RequestContext = a missing request-wrapping server\n// filter. We report that once (below), never on every line.\nconst MISSING_CONTEXT_MESSAGE =\n 'Log emitted OUTSIDE RequestContext.run(...) — every request must be wrapped in ' +\n 'RequestContext.run() by a server filter. That filter appears to be missing: correlation ' +\n 'fields (requestId, tenant, ...) will be absent from logs until it is added. Reported once.';\n\n// Above this serialized size the error is truncated, so one giant stack can't\n// blow up a log line (ported from the tested trytami AppLogger).\nconst MAX_ERR_SERIALIZED = 100_000;\n\nfunction truncateStack(stack: string | undefined, maxLines = 5): string {\n if (!stack) {\n return '';\n }\n return stack.split('\\n').slice(0, maxLines).join('\\n');\n}\n\nfunction normalizeError(err: Error): LoggedError {\n const full = new LoggedError(err.name, err.message, err.stack);\n if (JSON.stringify({ err: full }).length <= MAX_ERR_SERIALIZED) {\n return full;\n }\n return new LoggedError(\n `error too long: ${err.name}`,\n err.message.substring(0, 100),\n truncateStack(err.stack, 5),\n );\n}\n\n/**\n * BunyanLogger - a webpieces {@link WpLogger} backed by a bunyan logger (one per\n * name, created as a bunyan child carrying `loggerName`). On every call it reads\n * the logged HeaderRegistry keys DIRECTLY from the active {@link RequestContext}\n * (secured values masked) into the bunyan fields object, and normalizes an optional\n * Error into `err: { name, message, stack }` — matching the tested trytami AppLogger.\n * The GCP stream then serializes those fields into the structured log payload.\n *\n * This context-reading is INLINED here (and duplicated in the winston logger) on\n * purpose: it must run ONLY when a bunyan/winston backend is installed, never for\n * the plain ConsoleLogger — so it does not belong on RequestContext.\n */\nexport class BunyanLogger implements WpLogger {\n // One-shot latch (see MISSING_CONTEXT_MESSAGE) — flips true after the first\n // out-of-context line so we report the missing filter exactly once, not per line.\n private reportedMissingContext = false;\n\n constructor(private readonly bunyan: Logger) {}\n\n trace(message: string, err?: Error): void {\n this.bunyan.trace(this.buildFields(err), message);\n }\n\n debug(message: string, err?: Error): void {\n this.bunyan.debug(this.buildFields(err), message);\n }\n\n info(message: string, err?: Error): void {\n this.bunyan.info(this.buildFields(err), message);\n }\n\n warn(message: string, err?: Error): void {\n this.bunyan.warn(this.buildFields(err), message);\n }\n\n error(message: string, err?: Error): void {\n this.bunyan.error(this.buildFields(err), message);\n }\n\n private buildFields(err?: Error): Record<string, string | object | LoggedError> {\n const fields: Record<string, string | object | LoggedError> = {};\n if (!RequestContext.isActive()) {\n this.reportMissingContextOnce();\n return fields;\n }\n\n // ONE loop, in HeaderRegistry.buildStructuredLogFields — the registry owns the keys and each\n // ContextKey masks its own value. Values may be OBJECTS (the `api` tag), so an object-valued key\n // nests into the structured payload (bunyan's GCP stream serializes fields) rather than being\n // dropped by the string-only buildLogFields.\n RequestContext.buildStructuredLogFields().forEach((value: string | object, name: string) => {\n fields[name] = value;\n });\n if (err) {\n fields['err'] = normalizeError(err);\n }\n return fields;\n }\n\n // Report the missing request-wrapping filter once. Uses the RAW bunyan logger\n // (not buildFields()), so there is no re-entrancy — just a single extra line.\n private reportMissingContextOnce(): void {\n if (this.reportedMissingContext) {\n return;\n }\n this.reportedMissingContext = true;\n this.bunyan.error(MISSING_CONTEXT_MESSAGE);\n }\n}\n"]}
|