@webpieces/bunyan 0.4.399 → 0.4.400

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/bunyan",
3
- "version": "0.4.399",
3
+ "version": "0.4.400",
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.4.399",
27
- "@webpieces/core-context": "0.4.399",
26
+ "@webpieces/core-util": "0.4.400",
27
+ "@webpieces/core-context": "0.4.400",
28
28
  "bunyan": "1.8.15",
29
29
  "@google-cloud/logging-bunyan": "5.1.0",
30
30
  "@types/bunyan": "1.8.11"
@@ -5,21 +5,8 @@ import type { Logger as WpLogger, LoggerFactory } from '@webpieces/core-util';
5
5
  * backends. Builds ONE underlying bunyan logger with the caller-chosen stream,
6
6
  * then hands out a cached {@link BunyanLogger} per name (each a bunyan child
7
7
  * carrying `loggerName`). Every logger reads the magic context DIRECTLY from
8
- * RequestContext, so nothing is threaded through here. Subclasses differ only in
9
- * the stream they pass up (GCP vs local console).
10
- *
11
- * The root logger's `name` is bunyan's ONE mandatory option (its constructor throws
12
- * `options.name (string) is required`), and it comes from {@link ServiceInfo} — so an
13
- * app names itself ONCE, in one place, for logging AND for requestIdSource. Reading it
14
- * here means a forgotten `ServiceInfo.setInfo(...)` throws OUR actionable error while
15
- * the process boots, rather than bunyan's opaque TypeError.
16
- *
17
- * `version` rides alongside as a bunyan BASE FIELD (bunyan passes unknown top-level options straight
18
- * onto every record — it strips only stream/streams/level/serializers/src, and its own format
19
- * version is `v`, so there is no collision). This backend previously could not stamp a version at
20
- * all: it lived on winston's factory options, which made "do my logs say which build emitted them?"
21
- * depend on the logging library rather than on the service. Both backends now read the ONE
22
- * {@link ServiceInfo}.
8
+ * RequestContext (including the build `version`), so nothing is threaded through here. Subclasses
9
+ * differ only in the stream they pass up (GCP vs local console).
23
10
  *
24
11
  * Per-logger names ride as `loggerName` on each child rather than `name`, because
25
12
  * bunyan REFUSES to let a child override `name` (`invalid options.name: child cannot
@@ -3,28 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BunyanFactoryBase = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const bunyan_1 = tslib_1.__importDefault(require("bunyan"));
6
- const core_util_1 = require("@webpieces/core-util");
7
6
  const BunyanLogger_1 = require("./BunyanLogger");
7
+ /**
8
+ * bunyan's ONE mandatory option is a non-empty root-logger `name` (its constructor throws
9
+ * `options.name (string) is required`). It is NOT the service name: the service identity is a
10
+ * process-global {@link ServiceInfo} fact that may not be set yet when this factory is constructed
11
+ * (logging must work before `setInfo`), and a bunyan root `name` is baked at `createLogger` and can
12
+ * never change afterwards (children throw `child cannot set logger name`). So we feed bunyan a fixed
13
+ * placeholder here and stamp the real build `version` per-record via {@link RequestContext.buildStructuredLogFields}
14
+ * (the ONE map both backends read), where it appears the moment `setInfo` runs. Locally the field is
15
+ * suppressed anyway (see BUNYAN_STD_FIELDS in ./streams).
16
+ */
17
+ const BUNYAN_ROOT_NAME = 'app';
8
18
  /**
9
19
  * BunyanFactoryBase - shared plumbing for the bunyan {@link LoggerFactory}
10
20
  * backends. Builds ONE underlying bunyan logger with the caller-chosen stream,
11
21
  * then hands out a cached {@link BunyanLogger} per name (each a bunyan child
12
22
  * carrying `loggerName`). Every logger reads the magic context DIRECTLY from
13
- * RequestContext, so nothing is threaded through here. Subclasses differ only in
14
- * the stream they pass up (GCP vs local console).
15
- *
16
- * The root logger's `name` is bunyan's ONE mandatory option (its constructor throws
17
- * `options.name (string) is required`), and it comes from {@link ServiceInfo} — so an
18
- * app names itself ONCE, in one place, for logging AND for requestIdSource. Reading it
19
- * here means a forgotten `ServiceInfo.setInfo(...)` throws OUR actionable error while
20
- * the process boots, rather than bunyan's opaque TypeError.
21
- *
22
- * `version` rides alongside as a bunyan BASE FIELD (bunyan passes unknown top-level options straight
23
- * onto every record — it strips only stream/streams/level/serializers/src, and its own format
24
- * version is `v`, so there is no collision). This backend previously could not stamp a version at
25
- * all: it lived on winston's factory options, which made "do my logs say which build emitted them?"
26
- * depend on the logging library rather than on the service. Both backends now read the ONE
27
- * {@link ServiceInfo}.
23
+ * RequestContext (including the build `version`), so nothing is threaded through here. Subclasses
24
+ * differ only in the stream they pass up (GCP vs local console).
28
25
  *
29
26
  * Per-logger names ride as `loggerName` on each child rather than `name`, because
30
27
  * bunyan REFUSES to let a child override `name` (`invalid options.name: child cannot
@@ -35,8 +32,7 @@ class BunyanFactoryBase {
35
32
  loggers = new Map();
36
33
  constructor(streams) {
37
34
  this.base = bunyan_1.default.createLogger({
38
- name: core_util_1.ServiceInfo.getName(),
39
- version: core_util_1.ServiceInfo.getVersion(),
35
+ name: BUNYAN_ROOT_NAME,
40
36
  streams,
41
37
  });
42
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BunyanFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/bunyan/src/BunyanFactoryBase.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAE5B,oDAAmD;AACnD,iDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAsB,iBAAiB;IAClB,IAAI,CAAS;IACb,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEvD,YAAsB,OAAwB;QAC1C,IAAI,CAAC,IAAI,GAAG,gBAAM,CAAC,YAAY,CAAC;YAC5B,IAAI,EAAE,uBAAW,CAAC,OAAO,EAAE;YAC3B,OAAO,EAAE,uBAAW,CAAC,UAAU,EAAE;YACjC,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,IAAY;QAClB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AApBD,8CAoBC","sourcesContent":["import Logger from 'bunyan';\nimport type { Logger as WpLogger, LoggerFactory } from '@webpieces/core-util';\nimport { ServiceInfo } from '@webpieces/core-util';\nimport { BunyanLogger } from './BunyanLogger';\n\n/**\n * BunyanFactoryBase - shared plumbing for the bunyan {@link LoggerFactory}\n * backends. Builds ONE underlying bunyan logger with the caller-chosen stream,\n * then hands out a cached {@link BunyanLogger} per name (each a bunyan child\n * carrying `loggerName`). Every logger reads the magic context DIRECTLY from\n * RequestContext, so nothing is threaded through here. Subclasses differ only in\n * the stream they pass up (GCP vs local console).\n *\n * The root logger's `name` is bunyan's ONE mandatory option (its constructor throws\n * `options.name (string) is required`), and it comes from {@link ServiceInfo} — so an\n * app names itself ONCE, in one place, for logging AND for requestIdSource. Reading it\n * here means a forgotten `ServiceInfo.setInfo(...)` throws OUR actionable error while\n * the process boots, rather than bunyan's opaque TypeError.\n *\n * `version` rides alongside as a bunyan BASE FIELD (bunyan passes unknown top-level options straight\n * onto every record it strips only stream/streams/level/serializers/src, and its own format\n * version is `v`, so there is no collision). This backend previously could not stamp a version at\n * all: it lived on winston's factory options, which made \"do my logs say which build emitted them?\"\n * depend on the logging library rather than on the service. Both backends now read the ONE\n * {@link ServiceInfo}.\n *\n * Per-logger names ride as `loggerName` on each child rather than `name`, because\n * bunyan REFUSES to let a child override `name` (`invalid options.name: child cannot\n * set logger name`).\n */\nexport abstract class BunyanFactoryBase implements LoggerFactory {\n private readonly base: Logger;\n private readonly loggers = new Map<string, WpLogger>();\n\n protected constructor(streams: Logger.Stream[]) {\n this.base = Logger.createLogger({\n name: ServiceInfo.getName(),\n version: ServiceInfo.getVersion(),\n streams,\n });\n }\n\n getLogger(name: string): WpLogger {\n let logger = this.loggers.get(name);\n if (!logger) {\n logger = new BunyanLogger(this.base.child({ loggerName: name }));\n this.loggers.set(name, logger);\n }\n return logger;\n }\n}\n"]}
1
+ {"version":3,"file":"BunyanFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/bunyan/src/BunyanFactoryBase.ts"],"names":[],"mappings":";;;;AAAA,4DAA4B;AAE5B,iDAA8C;AAE9C;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B;;;;;;;;;;;GAWG;AACH,MAAsB,iBAAiB;IAClB,IAAI,CAAS;IACb,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEvD,YAAsB,OAAwB;QAC1C,IAAI,CAAC,IAAI,GAAG,gBAAM,CAAC,YAAY,CAAC;YAC5B,IAAI,EAAE,gBAAgB;YACtB,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,IAAY;QAClB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAnBD,8CAmBC","sourcesContent":["import Logger from 'bunyan';\nimport type { Logger as WpLogger, LoggerFactory } from '@webpieces/core-util';\nimport { BunyanLogger } from './BunyanLogger';\n\n/**\n * bunyan's ONE mandatory option is a non-empty root-logger `name` (its constructor throws\n * `options.name (string) is required`). It is NOT the service name: the service identity is a\n * process-global {@link ServiceInfo} fact that may not be set yet when this factory is constructed\n * (logging must work before `setInfo`), and a bunyan root `name` is baked at `createLogger` and can\n * never change afterwards (children throw `child cannot set logger name`). So we feed bunyan a fixed\n * placeholder here and stamp the real build `version` per-record via {@link RequestContext.buildStructuredLogFields}\n * (the ONE map both backends read), where it appears the moment `setInfo` runs. Locally the field is\n * suppressed anyway (see BUNYAN_STD_FIELDS in ./streams).\n */\nconst BUNYAN_ROOT_NAME = 'app';\n\n/**\n * BunyanFactoryBase - shared plumbing for the bunyan {@link LoggerFactory}\n * backends. Builds ONE underlying bunyan logger with the caller-chosen stream,\n * then hands out a cached {@link BunyanLogger} per name (each a bunyan child\n * carrying `loggerName`). Every logger reads the magic context DIRECTLY from\n * RequestContext (including the build `version`), so nothing is threaded through here. Subclasses\n * differ only in the stream they pass up (GCP vs local console).\n *\n * Per-logger names ride as `loggerName` on each child rather than `name`, because\n * bunyan REFUSES to let a child override `name` (`invalid options.name: child cannot\n * set logger name`).\n */\nexport abstract class BunyanFactoryBase implements LoggerFactory {\n private readonly base: Logger;\n private readonly loggers = new Map<string, WpLogger>();\n\n protected constructor(streams: Logger.Stream[]) {\n this.base = Logger.createLogger({\n name: BUNYAN_ROOT_NAME,\n streams,\n });\n }\n\n getLogger(name: string): WpLogger {\n let logger = this.loggers.get(name);\n if (!logger) {\n logger = new BunyanLogger(this.base.child({ loggerName: name }));\n this.loggers.set(name, logger);\n }\n return logger;\n }\n}\n"]}