@webpieces/winston 0.4.438 → 0.4.440
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/format.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/winston",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.440",
|
|
4
4
|
"description": "Node-only winston LoggerFactory backends for webpieces: Console (local pretty) + GCP (Cloud Run stdout JSON), 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.4.
|
|
27
|
-
"@webpieces/core-context": "0.4.
|
|
26
|
+
"@webpieces/core-util": "0.4.440",
|
|
27
|
+
"@webpieces/core-context": "0.4.440",
|
|
28
28
|
"winston": "3.11.0",
|
|
29
29
|
"logform": "2.7.0",
|
|
30
30
|
"safe-stable-stringify": "2.5.0"
|
package/src/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/format.ts"],"names":[],"mappings":";;;AA6CA,4CAeC;AAiBD,kDAmBC;AAMD,wCAKC;AA2DD,8CAqEC;AA3OD;;;;;;;;;;;;GAYG;AACH,qCAAiC;AAEjC,iEAAmE;AACnE,oDAAsE;AAEtE,0DAAyD;AAMzD,gFAAgF;AAChF,iFAAiF;AACjF,kFAAkF;AAClF,uDAAuD;AAC1C,QAAA,iBAAiB,GAA2B;IACrD,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;CACj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,CAAC,IAAI,IAAI,EAAE,CAAC;YACpF,IAAI,IAAI,kBAAkB,CAAC;YAC3B,IAAI,IAAI,gBAAgB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAC3D,IAAI,IAAI,aAAa,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YACrD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;gBAC3B,IAAI,IAAI,qBAAqB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAC5D,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["/**\n * The winston format layers that turn a raw webpieces log call into a\n * Cloud-Logging-ready structured record. Ported verbatim (behaviourally) from\n * the tested-in-GCP logger at\n * onetablet/monorepo-nx1 libraries/core-context/src/logger/format.ts, with the\n * one webpieces adaptation: context is read from the webpieces HeaderRegistry +\n * a ContextReader (rather than a hard-coded PLATFORM_HEADERS enum), so the exact\n * set of logged fields is whatever the app registered.\n *\n * Correlation rides the webpieces magic context (AsyncLocalStorage on the\n * server, via the ContextReader passed in) — NOT OpenTelemetry / trace-agent, so\n * nothing here imports a tracing agent.\n */\nimport { format } from 'winston';\nimport type { Format, TransformableInfo } from 'logform';\nimport { stringify as safeStringify } from 'safe-stable-stringify';\nimport { HeaderRegistry, ApiCallLogName } from '@webpieces/core-util';\nimport type { ContextKey } from '@webpieces/core-util';\nimport { RequestContext } from '@webpieces/core-context';\n\n// JSON-shaped value (the widest thing a log field / replacer value can hold),\n// used instead of `any`/`unknown` which the code rules disallow.\ntype JsonValue = string | number | boolean | bigint | object | null | undefined;\n\n// winston level → GCP Cloud Logging severity. The Cloud Run / GKE logging agent\n// recognises top-level `severity` in stdout JSON; without this map it falls back\n// to \"DEFAULT\" which is unfilterable. webpieces `trace` maps onto winston `silly`\n// (see WinstonLogger), so both land at DEBUG severity.\nexport const LEVEL_TO_SEVERITY: Record<string, string> = {\n silly: 'DEBUG',\n verbose: 'DEBUG',\n debug: 'DEBUG',\n info: 'INFO',\n warn: 'WARNING',\n error: 'ERROR',\n};\n\n/**\n * Round-trip the record through safe-stable-stringify so circular references\n * (HTTP client/response cycles, request/response objects, framework execution\n * contexts) become \"[Circular]\" instead of crashing the log emit, and bigints\n * serialize as strings (JSON.stringify can't, and the bare safe-stringify output\n * wouldn't round-trip through JSON.parse). Symbol keys winston relies on are\n * untouched (JSON ignores them), so Object.assign only rewrites string fields.\n */\nexport function bigIntSafeFormat(): Format {\n return format((info: TransformableInfo) => {\n return Object.assign(\n info,\n JSON.parse(\n // webpieces-disable no-any-unknown -- safe-stable-stringify's Replacer types the value as unknown\n safeStringify(info, (_key: string, value: unknown) => {\n if (typeof value === 'bigint') {\n return value.toString();\n }\n return value;\n })!,\n ),\n );\n })();\n}\n\n/**\n * Inject every logged HeaderRegistry key present in the active RequestContext frame\n * into the record under its `name` (→ top-level jsonPayload.<name> in GCP, filterable\n * as jsonPayload.requestId, jsonPayload.tenantId, …). Values are read DIRECTLY from\n * RequestContext, secured keys masked via {@link ContextKey.maskIfSecured} — no\n * ContextReader. Caller-supplied fields on the record win on conflict. Runs on EVERY\n * winston call, including winston's own handleExceptions/handleRejections lines that\n * bypass the WinstonLogger wrapper.\n *\n * This mirrors the (duplicated, on purpose) inline logic in BunyanLogger: it must run\n * ONLY when a winston backend is installed, never for the plain ConsoleLogger. A log\n * line with no active RequestContext just injects nothing (startup and background-job\n * lines are legitimately out of context).\n */\n// webpieces-disable no-function-outside-class -- winston format(fn) factory; whole file is winston Format factories\nexport function injectContextFormat(): Format {\n return format((info: TransformableInfo) => {\n // No active RequestContext (startup, a background job, or an in-process call the caller did\n // not wrap) simply injects nothing — an empty context is normal, not an error. The one place\n // a request-path wrap can legitimately be missing (the in-process client) is caught precisely\n // by ApiClientFactory.requireActiveContext(), which throws at the api boundary.\n if (RequestContext.isActive()) {\n // ONE loop, in HeaderRegistry.buildStructuredLogFields. Values may be OBJECTS (the `api`\n // tag), so an object-valued key nests into jsonPayload.<name> (winston JSON-serializes the\n // whole record) rather than being dropped by the string-only buildLogFields. Caller-supplied\n // fields win on conflict.\n RequestContext.buildStructuredLogFields().forEach((value: string | object, name: string) => {\n if (info[name] === undefined) {\n info[name] = value;\n }\n });\n }\n return info;\n })();\n}\n\n/**\n * Map the winston level onto a top-level `severity` field that the Cloud Logging\n * agent lifts onto the LogEntry.\n */\nexport function severityFormat(): Format {\n return format((info: TransformableInfo) => {\n info['severity'] = LEVEL_TO_SEVERITY[info.level] || info.level.toUpperCase();\n return info;\n })();\n}\n\n// The two context keys rendered SPECIALLY (as the compact `[Controller.method]` bracket) instead of as\n// `key:value` tags — they name WHICH CODE ran. Kept in sync with WebpiecesCoreHeaders.CONTROLLER / .METHOD.\nconst CONTROLLER_FIELD = 'controller';\nconst METHOD_FIELD = 'method';\n\n// winston level name → the webpieces display level shown in the console line. Mirrors bunyan's\n// Logger.nameFromLevel output so the two backends print IDENTICAL level tokens. webpieces `trace`\n// rides winston `silly` (see WinstonLogger); `verbose` is winston's own extra rung, shown as DEBUG.\nconst WINSTON_LEVEL_TO_DISPLAY: Record<string, string> = {\n silly: 'TRACE',\n verbose: 'DEBUG',\n debug: 'DEBUG',\n info: 'INFO',\n warn: 'WARN',\n error: 'ERROR',\n};\n\n// Fields that are rendered specially (or not at all) by the local pretty format,\n// so they must not leak into the trailing \"extra\" JSON blob.\n//\n// `svcName` + `version` (the ServiceInfo defaultMeta fields) are here to be rendered NOT AT ALL:\n// they earn their keep in GCP, where you filter across many services and deploys, but locally each\n// service logs to its own place and you can check git yourself — so on every single line they are\n// pure noise. GCP still gets both (this set only affects localPrettyFormat).\n//\n// `timestamp` (its own `[time]` slot), `loggerName` (its own `[…]` bracket) and `controller`/`method`\n// (the `[Controller.method]` bracket) are rendered specially. `errName`/`errMessage`/`errStack` (the\n// Error spread from WinstonLogger) render as the multi-line \"Error Details:\" block. All are excluded\n// here so none leak into the trailing JSON.\nconst LOCAL_STRUCTURAL_KEYS = new Set<string>([\n 'level',\n 'message',\n 'severity',\n 'svcName',\n 'version',\n 'loggerName',\n 'timestamp',\n CONTROLLER_FIELD,\n METHOD_FIELD,\n 'errName',\n 'errMessage',\n 'errStack',\n]);\n\n/**\n * Local-only human format:\n * `[LEVEL][time][Controller.method][loggerName][ctx tags]: message { …extra }` + Error Details block.\n * Level FIRST, then time (the ordering the trytami format was tuned for). `controller`/`method` render\n * as a compact bracket, `loggerName` as its own bracket, every other registered context key as a\n * `key:value` tag, and anything else the caller attached as trailing JSON. Byte-identical to the bunyan\n * backend for the same record + `fields`.\n *\n * `fields`, when given, is the app-chosen ordered ALLOW-LIST of context keys to render as tags (hides\n * local noise like `requestPath`); when omitted, the registered logged keys render in registry order.\n * The time value comes from the `format.timestamp({format:'HH:mm:ss.SSS'})` layer in WinstonConsoleFactory.\n */\n// webpieces-disable no-function-outside-class -- winston Format factory; whole file is winston Format factories\nexport function localPrettyFormat(fields?: string[]): Format {\n let contextNames: string[] | undefined;\n return format.printf((info: TransformableInfo) => {\n if (!contextNames) {\n contextNames = HeaderRegistry.get().getLoggedKeys().map((k: ContextKey) => k.name);\n }\n const levelName = (WINSTON_LEVEL_TO_DISPLAY[info.level] ?? info.level.toUpperCase()).padEnd(5);\n const time = info['timestamp'] != null ? String(info['timestamp']) : '';\n\n // The compact `[Controller.method]` bracket (or `[Controller]`, or '' when neither is present —\n // a startup / static / pre-route line). Empty controller drops the whole bracket.\n const controller = info[CONTROLLER_FIELD];\n const method = info[METHOD_FIELD];\n const controllerMethod =\n typeof controller === 'string' && controller.length > 0\n ? `[${controller}${typeof method === 'string' && method.length > 0 ? `.${method}` : ''}]`\n : '';\n // LogApiCall lines render as a self-describing [API.{side}.{phase}] bracket instead of the opaque\n // [LogApiCall]; every other line keeps its plain [loggerName] bracket. (info indexes to `unknown`.)\n const loggerBracket = ApiCallLogName.bracket(\n info['loggerName'] as string | undefined, info['api'] as object | undefined);\n\n // Ordered `key:value` context tags. `fields` (allow-list) wins; else the registered logged keys.\n // Only STRING values render (an object-valued key like `api` is dropped here and falls into the\n // trailing JSON blob below, while GCP still gets it nested). controller/method/loggerName are\n // rendered in their own brackets, so they are skipped here.\n const order = fields ?? contextNames;\n const tags: string[] = [];\n for (const name of order) {\n if (name === CONTROLLER_FIELD || name === METHOD_FIELD || name === 'loggerName') {\n continue;\n }\n const value = info[name];\n if (value != null && typeof value === 'string' && value.length > 0) {\n tags.push(`${name}:${value}`);\n }\n }\n const tagStr = tags.length > 0 ? tags.join(', ') : 'no-context';\n\n const contextNameSet = new Set(contextNames);\n const rest: Record<string, JsonValue> = {};\n for (const key of Object.keys(info)) {\n if (LOCAL_STRUCTURAL_KEYS.has(key)) {\n continue;\n }\n // A registered context key already shown as a string tag is skipped; an object-valued\n // context key (api) was NOT shown there, so let it render as trailing JSON.\n if (contextNameSet.has(key) && typeof info[key] === 'string') {\n continue;\n }\n rest[key] = info[key] as JsonValue;\n }\n const restStr = Object.keys(rest).length ? ` ${safeStringify(rest)}` : '';\n\n let line = `[${levelName}][${time}]${controllerMethod}${loggerBracket}[${tagStr}]: ${info.message}${restStr}`;\n\n // Multi-line error block, byte-identical to the bunyan backend. WinstonLogger spreads an Error\n // into errName/errMessage/errStack; render them the same way trytami's writeConsole did.\n if (info['errName'] != null || info['errMessage'] != null || info['errStack'] != null) {\n line += `\\nError Details:`;\n line += `\\n Message: ${String(info['errMessage'] ?? '')}`;\n line += `\\n Name: ${String(info['errName'] ?? '')}`;\n if (info['errStack'] != null) {\n line += `\\n Stack Trace:\\n${String(info['errStack'])}`;\n }\n }\n\n return line;\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/format.ts"],"names":[],"mappings":";;;AA6CA,4CAeC;AAiBD,kDAmBC;AAMD,wCAKC;AA2DD,8CAqEC;AA3OD;;;;;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AC,CAAC,CAAC,EAAE,CAAC;QAE1E,IAAI,IAAI,GAAG,IAAI,SAAS,KAAK,IAAI,IAAI,gBAAgB,GAAG,aAAa,IAAI,MAAM,MAAM,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;QAE9G,+FAA+F;QAC/F,yFAAyF;QACzF,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;YACpF,IAAI,IAAI,kBAAkB,CAAC;YAC3B,IAAI,IAAI,gBAAgB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAC3D,IAAI,IAAI,aAAa,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YACrD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;gBAC3B,IAAI,IAAI,qBAAqB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAC5D,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["/**\n * The winston format layers that turn a raw webpieces log call into a\n * Cloud-Logging-ready structured record. Ported verbatim (behaviourally) from\n * the tested-in-GCP logger at\n * onetablet/monorepo-nx1 libraries/core-context/src/logger/format.ts, with the\n * one webpieces adaptation: context is read from the webpieces HeaderRegistry +\n * a ContextReader (rather than a hard-coded PLATFORM_HEADERS enum), so the exact\n * set of logged fields is whatever the app registered.\n *\n * Correlation rides the webpieces magic context (AsyncLocalStorage on the\n * server, via the ContextReader passed in) — NOT OpenTelemetry / trace-agent, so\n * nothing here imports a tracing agent.\n */\nimport { format } from 'winston';\nimport type { Format, TransformableInfo } from 'logform';\nimport { stringify as safeStringify } from 'safe-stable-stringify';\nimport { HeaderRegistry, ApiCallLogName } from '@webpieces/core-util';\nimport type { ContextKey, AnyContextKey } from '@webpieces/core-util';\nimport { RequestContext } from '@webpieces/core-context';\n\n// JSON-shaped value (the widest thing a log field / replacer value can hold),\n// used instead of `any`/`unknown` which the code rules disallow.\ntype JsonValue = string | number | boolean | bigint | object | null | undefined;\n\n// winston level → GCP Cloud Logging severity. The Cloud Run / GKE logging agent\n// recognises top-level `severity` in stdout JSON; without this map it falls back\n// to \"DEFAULT\" which is unfilterable. webpieces `trace` maps onto winston `silly`\n// (see WinstonLogger), so both land at DEBUG severity.\nexport const LEVEL_TO_SEVERITY: Record<string, string> = {\n silly: 'DEBUG',\n verbose: 'DEBUG',\n debug: 'DEBUG',\n info: 'INFO',\n warn: 'WARNING',\n error: 'ERROR',\n};\n\n/**\n * Round-trip the record through safe-stable-stringify so circular references\n * (HTTP client/response cycles, request/response objects, framework execution\n * contexts) become \"[Circular]\" instead of crashing the log emit, and bigints\n * serialize as strings (JSON.stringify can't, and the bare safe-stringify output\n * wouldn't round-trip through JSON.parse). Symbol keys winston relies on are\n * untouched (JSON ignores them), so Object.assign only rewrites string fields.\n */\nexport function bigIntSafeFormat(): Format {\n return format((info: TransformableInfo) => {\n return Object.assign(\n info,\n JSON.parse(\n // webpieces-disable no-any-unknown -- safe-stable-stringify's Replacer types the value as unknown\n safeStringify(info, (_key: string, value: unknown) => {\n if (typeof value === 'bigint') {\n return value.toString();\n }\n return value;\n })!,\n ),\n );\n })();\n}\n\n/**\n * Inject every logged HeaderRegistry key present in the active RequestContext frame\n * into the record under its `name` (→ top-level jsonPayload.<name> in GCP, filterable\n * as jsonPayload.requestId, jsonPayload.tenantId, …). Values are read DIRECTLY from\n * RequestContext, secured keys masked via {@link ContextKey.maskIfSecured} — no\n * ContextReader. Caller-supplied fields on the record win on conflict. Runs on EVERY\n * winston call, including winston's own handleExceptions/handleRejections lines that\n * bypass the WinstonLogger wrapper.\n *\n * This mirrors the (duplicated, on purpose) inline logic in BunyanLogger: it must run\n * ONLY when a winston backend is installed, never for the plain ConsoleLogger. A log\n * line with no active RequestContext just injects nothing (startup and background-job\n * lines are legitimately out of context).\n */\n// webpieces-disable no-function-outside-class -- winston format(fn) factory; whole file is winston Format factories\nexport function injectContextFormat(): Format {\n return format((info: TransformableInfo) => {\n // No active RequestContext (startup, a background job, or an in-process call the caller did\n // not wrap) simply injects nothing — an empty context is normal, not an error. The one place\n // a request-path wrap can legitimately be missing (the in-process client) is caught precisely\n // by ApiClientFactory.requireActiveContext(), which throws at the api boundary.\n if (RequestContext.isActive()) {\n // ONE loop, in HeaderRegistry.buildStructuredLogFields. Values may be OBJECTS (the `api`\n // tag), so an object-valued key nests into jsonPayload.<name> (winston JSON-serializes the\n // whole record) rather than being dropped by the string-only buildLogFields. Caller-supplied\n // fields win on conflict.\n RequestContext.buildStructuredLogFields().forEach((value: string | object, name: string) => {\n if (info[name] === undefined) {\n info[name] = value;\n }\n });\n }\n return info;\n })();\n}\n\n/**\n * Map the winston level onto a top-level `severity` field that the Cloud Logging\n * agent lifts onto the LogEntry.\n */\nexport function severityFormat(): Format {\n return format((info: TransformableInfo) => {\n info['severity'] = LEVEL_TO_SEVERITY[info.level] || info.level.toUpperCase();\n return info;\n })();\n}\n\n// The two context keys rendered SPECIALLY (as the compact `[Controller.method]` bracket) instead of as\n// `key:value` tags — they name WHICH CODE ran. Kept in sync with WebpiecesCoreHeaders.CONTROLLER / .METHOD.\nconst CONTROLLER_FIELD = 'controller';\nconst METHOD_FIELD = 'method';\n\n// winston level name → the webpieces display level shown in the console line. Mirrors bunyan's\n// Logger.nameFromLevel output so the two backends print IDENTICAL level tokens. webpieces `trace`\n// rides winston `silly` (see WinstonLogger); `verbose` is winston's own extra rung, shown as DEBUG.\nconst WINSTON_LEVEL_TO_DISPLAY: Record<string, string> = {\n silly: 'TRACE',\n verbose: 'DEBUG',\n debug: 'DEBUG',\n info: 'INFO',\n warn: 'WARN',\n error: 'ERROR',\n};\n\n// Fields that are rendered specially (or not at all) by the local pretty format,\n// so they must not leak into the trailing \"extra\" JSON blob.\n//\n// `svcName` + `version` (the ServiceInfo defaultMeta fields) are here to be rendered NOT AT ALL:\n// they earn their keep in GCP, where you filter across many services and deploys, but locally each\n// service logs to its own place and you can check git yourself — so on every single line they are\n// pure noise. GCP still gets both (this set only affects localPrettyFormat).\n//\n// `timestamp` (its own `[time]` slot), `loggerName` (its own `[…]` bracket) and `controller`/`method`\n// (the `[Controller.method]` bracket) are rendered specially. `errName`/`errMessage`/`errStack` (the\n// Error spread from WinstonLogger) render as the multi-line \"Error Details:\" block. All are excluded\n// here so none leak into the trailing JSON.\nconst LOCAL_STRUCTURAL_KEYS = new Set<string>([\n 'level',\n 'message',\n 'severity',\n 'svcName',\n 'version',\n 'loggerName',\n 'timestamp',\n CONTROLLER_FIELD,\n METHOD_FIELD,\n 'errName',\n 'errMessage',\n 'errStack',\n]);\n\n/**\n * Local-only human format:\n * `[LEVEL][time][Controller.method][loggerName][ctx tags]: message { …extra }` + Error Details block.\n * Level FIRST, then time (the ordering the trytami format was tuned for). `controller`/`method` render\n * as a compact bracket, `loggerName` as its own bracket, every other registered context key as a\n * `key:value` tag, and anything else the caller attached as trailing JSON. Byte-identical to the bunyan\n * backend for the same record + `fields`.\n *\n * `fields`, when given, is the app-chosen ordered ALLOW-LIST of context keys to render as tags (hides\n * local noise like `requestPath`); when omitted, the registered logged keys render in registry order.\n * The time value comes from the `format.timestamp({format:'HH:mm:ss.SSS'})` layer in WinstonConsoleFactory.\n */\n// webpieces-disable no-function-outside-class -- winston Format factory; whole file is winston Format factories\nexport function localPrettyFormat(fields?: string[]): Format {\n let contextNames: string[] | undefined;\n return format.printf((info: TransformableInfo) => {\n if (!contextNames) {\n contextNames = HeaderRegistry.get().getLoggedKeys().map((k: AnyContextKey) => k.name);\n }\n const levelName = (WINSTON_LEVEL_TO_DISPLAY[info.level] ?? info.level.toUpperCase()).padEnd(5);\n const time = info['timestamp'] != null ? String(info['timestamp']) : '';\n\n // The compact `[Controller.method]` bracket (or `[Controller]`, or '' when neither is present —\n // a startup / static / pre-route line). Empty controller drops the whole bracket.\n const controller = info[CONTROLLER_FIELD];\n const method = info[METHOD_FIELD];\n const controllerMethod =\n typeof controller === 'string' && controller.length > 0\n ? `[${controller}${typeof method === 'string' && method.length > 0 ? `.${method}` : ''}]`\n : '';\n // LogApiCall lines render as a self-describing [API.{side}.{phase}] bracket instead of the opaque\n // [LogApiCall]; every other line keeps its plain [loggerName] bracket. (info indexes to `unknown`.)\n const loggerBracket = ApiCallLogName.bracket(\n info['loggerName'] as string | undefined, info['api'] as object | undefined);\n\n // Ordered `key:value` context tags. `fields` (allow-list) wins; else the registered logged keys.\n // Only STRING values render (an object-valued key like `api` is dropped here and falls into the\n // trailing JSON blob below, while GCP still gets it nested). controller/method/loggerName are\n // rendered in their own brackets, so they are skipped here.\n const order = fields ?? contextNames;\n const tags: string[] = [];\n for (const name of order) {\n if (name === CONTROLLER_FIELD || name === METHOD_FIELD || name === 'loggerName') {\n continue;\n }\n const value = info[name];\n if (value != null && typeof value === 'string' && value.length > 0) {\n tags.push(`${name}:${value}`);\n }\n }\n const tagStr = tags.length > 0 ? tags.join(', ') : 'no-context';\n\n const contextNameSet = new Set(contextNames);\n const rest: Record<string, JsonValue> = {};\n for (const key of Object.keys(info)) {\n if (LOCAL_STRUCTURAL_KEYS.has(key)) {\n continue;\n }\n // A registered context key already shown as a string tag is skipped; an object-valued\n // context key (api) was NOT shown there, so let it render as trailing JSON.\n if (contextNameSet.has(key) && typeof info[key] === 'string') {\n continue;\n }\n rest[key] = info[key] as JsonValue;\n }\n const restStr = Object.keys(rest).length ? ` ${safeStringify(rest)}` : '';\n\n let line = `[${levelName}][${time}]${controllerMethod}${loggerBracket}[${tagStr}]: ${info.message}${restStr}`;\n\n // Multi-line error block, byte-identical to the bunyan backend. WinstonLogger spreads an Error\n // into errName/errMessage/errStack; render them the same way trytami's writeConsole did.\n if (info['errName'] != null || info['errMessage'] != null || info['errStack'] != null) {\n line += `\\nError Details:`;\n line += `\\n Message: ${String(info['errMessage'] ?? '')}`;\n line += `\\n Name: ${String(info['errName'] ?? '')}`;\n if (info['errStack'] != null) {\n line += `\\n Stack Trace:\\n${String(info['errStack'])}`;\n }\n }\n\n return line;\n });\n}\n"]}
|