@webpieces/winston 0.4.412 → 0.4.414
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/WinstonFactoryBase.js +2 -1
- package/src/WinstonFactoryBase.js.map +1 -1
- package/src/index.d.ts +6 -3
- package/src/index.js +6 -3
- package/src/index.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.414",
|
|
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.414",
|
|
27
|
+
"@webpieces/core-context": "0.4.414",
|
|
28
28
|
"winston": "3.11.0",
|
|
29
29
|
"logform": "2.7.0",
|
|
30
30
|
"safe-stable-stringify": "2.5.0"
|
|
@@ -32,7 +32,8 @@ class WinstonFactoryBase {
|
|
|
32
32
|
constructor(finalFormat, transport) {
|
|
33
33
|
// svcName is a base field on every record when known. Non-throwing read: if the service was
|
|
34
34
|
// not identified before this factory was built, svcName is simply omitted rather than blocking
|
|
35
|
-
// the deploy — setupRuntime
|
|
35
|
+
// the deploy — setupRuntime identifies the service via ServiceInfo.setInfo (name+version are
|
|
36
|
+
// required inputs) before it serves traffic.
|
|
36
37
|
const svcName = core_util_1.ServiceInfo.getName();
|
|
37
38
|
const defaultMeta = {};
|
|
38
39
|
if (svcName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WinstonFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/WinstonFactoryBase.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAKnD,oDAAmD;AACnD,mDAAgD;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAsB,kBAAkB;IACnB,IAAI,CAAc;IAClB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD;;;;;OAKG;IACH,YAAsB,WAAmB,EAAE,SAAqB;QAC5D,4FAA4F;QAC5F,+FAA+F;QAC/F,6FAA6F;QAC7F,MAAM,OAAO,GAAG,uBAAW,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,WAAW,GAA2B,EAAE,CAAC;QAC/C,IAAI,OAAO,EAAE,CAAC;YACV,WAAW,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;QACrC,CAAC;QAED,+EAA+E;QAC/E,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAY,EAAC;YACrB,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,WAAW;YACxB,UAAU,EAAE,CAAC,SAAS,IAAI,IAAI,oBAAU,CAAC,OAAO,EAAE,CAAC;YACnD,gBAAgB,EAAE,IAAI;YACtB,gBAAgB,EAAE,IAAI;SACzB,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,6BAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;
|
|
1
|
+
{"version":3,"file":"WinstonFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/WinstonFactoryBase.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAKnD,oDAAmD;AACnD,mDAAgD;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAsB,kBAAkB;IACnB,IAAI,CAAc;IAClB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD;;;;;OAKG;IACH,YAAsB,WAAmB,EAAE,SAAqB;QAC5D,4FAA4F;QAC5F,+FAA+F;QAC/F,6FAA6F;QAC7F,6CAA6C;QAC7C,MAAM,OAAO,GAAG,uBAAW,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,WAAW,GAA2B,EAAE,CAAC;QAC/C,IAAI,OAAO,EAAE,CAAC;YACV,WAAW,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;QACrC,CAAC;QAED,+EAA+E;QAC/E,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAY,EAAC;YACrB,MAAM,EAAE,WAAW;YACnB,WAAW,EAAE,WAAW;YACxB,UAAU,EAAE,CAAC,SAAS,IAAI,IAAI,oBAAU,CAAC,OAAO,EAAE,CAAC;YACnD,gBAAgB,EAAE,IAAI;YACtB,gBAAgB,EAAE,IAAI;SACzB,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,6BAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAvCD,gDAuCC","sourcesContent":["import { createLogger, transports } from 'winston';\nimport type { Logger as WinstonBase } from 'winston';\nimport type Transport from 'winston-transport';\nimport type { Format } from 'logform';\nimport type { Logger, LoggerFactory } from '@webpieces/core-util';\nimport { ServiceInfo } from '@webpieces/core-util';\nimport { WinstonLogger } from './WinstonLogger';\n\n/**\n * WinstonFactoryBase - shared plumbing for the winston {@link LoggerFactory}\n * backends. Builds ONE underlying winston logger (a single `Console` transport,\n * handleExceptions/Rejections on) with the caller-chosen format stack, then hands\n * out a cached {@link WinstonLogger} per name (each a winston child carrying\n * `loggerName`). Subclasses differ only in the format stack they pass up.\n *\n * Every line carries `svcName` from {@link ServiceInfo} (winston has no mandatory logger name, so this\n * backend used to emit none — a winston service was distinguishable only by GCP's own resource\n * labels). It is read here at construction and rides as `defaultMeta`; it is simply absent if the\n * service was not identified before this factory was built.\n *\n * `version` is NOT read here: it is stamped per-record by `RequestContext.buildStructuredLogFields`\n * (the one map `injectContextFormat` already loops), so it appears the moment `setInfo` runs — even\n * if that is after this factory was constructed — and logging works before it.\n */\nexport abstract class WinstonFactoryBase implements LoggerFactory {\n private readonly base: WinstonBase;\n private readonly loggers = new Map<string, Logger>();\n\n /**\n * @param transport - the sink to write through. Defaults to a plain Console; the GCP subclass\n * passes a {@link ChunkingConsoleTransport} instead, because only there does a per-entry size\n * limit exist. Taking the whole transport (rather than a size knob) keeps the size limit a fact\n * about the SINK, which is where it actually lives — a dev terminal has no such limit.\n */\n protected constructor(finalFormat: Format, transport?: Transport) {\n // svcName is a base field on every record when known. Non-throwing read: if the service was\n // not identified before this factory was built, svcName is simply omitted rather than blocking\n // the deploy — setupRuntime identifies the service via ServiceInfo.setInfo (name+version are\n // required inputs) before it serves traffic.\n const svcName = ServiceInfo.getName();\n const defaultMeta: Record<string, string> = {};\n if (svcName) {\n defaultMeta['svcName'] = svcName;\n }\n\n // No level set — we do NOT filter; that is winston's job (defaults to 'info').\n this.base = createLogger({\n format: finalFormat,\n defaultMeta: defaultMeta,\n transports: [transport ?? new transports.Console()],\n handleExceptions: true,\n handleRejections: true,\n });\n }\n\n getLogger(name: string): Logger {\n let logger = this.loggers.get(name);\n if (!logger) {\n logger = new WinstonLogger(this.base.child({ loggerName: name }));\n this.loggers.set(name, logger);\n }\n return logger;\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
* startup via `LogManager.setFactory(...)`:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
|
-
* import { ServiceInfo } from '@webpieces/core-util';
|
|
9
8
|
* import { WinstonGcpFactory, WinstonConsoleFactory } from '@webpieces/winston';
|
|
10
9
|
*
|
|
11
|
-
* ServiceInfo.setInfo('my-service', '2.1.0'); // FIRST — the factories read it in their constructor
|
|
12
10
|
* const loggerFactory = process.env.K_SERVICE
|
|
13
11
|
* ? new WinstonGcpFactory() // Cloud Run → stdout JSON
|
|
14
12
|
* : new WinstonConsoleFactory(); // local → pretty console
|
|
15
|
-
* //
|
|
13
|
+
* // setupRuntime identifies the service (name+version are REQUIRED inputs) and installs the backend:
|
|
14
|
+
* // setupRuntime(new RuntimeSetupOptions('my-service', '2.1.0', loggerFactory, ...))
|
|
16
15
|
* ```
|
|
17
16
|
*
|
|
17
|
+
* (svcName rides winston `defaultMeta`, read at factory CONSTRUCTION — so if you need it on winston
|
|
18
|
+
* lines, call `ServiceInfo.setInfo('my-service', '2.1.0')` before building the factory too; `version`
|
|
19
|
+
* is stamped per-record and appears the moment setupRuntime runs regardless of construction order.)
|
|
20
|
+
*
|
|
18
21
|
* BREAKING (was `new WinstonFactoryOptions(svcGitHash)` passed to each factory): the version moved
|
|
19
22
|
* to `ServiceInfo.setInfo(name, version)` in @webpieces/core-util, because it is a fact about the
|
|
20
23
|
* SERVICE, not about winston — bunyan needs the same version and previously could not stamp one at
|
package/src/index.js
CHANGED
|
@@ -8,16 +8,19 @@ exports.localPrettyFormat = exports.severityFormat = exports.injectContextFormat
|
|
|
8
8
|
* startup via `LogManager.setFactory(...)`:
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* import { ServiceInfo } from '@webpieces/core-util';
|
|
12
11
|
* import { WinstonGcpFactory, WinstonConsoleFactory } from '@webpieces/winston';
|
|
13
12
|
*
|
|
14
|
-
* ServiceInfo.setInfo('my-service', '2.1.0'); // FIRST — the factories read it in their constructor
|
|
15
13
|
* const loggerFactory = process.env.K_SERVICE
|
|
16
14
|
* ? new WinstonGcpFactory() // Cloud Run → stdout JSON
|
|
17
15
|
* : new WinstonConsoleFactory(); // local → pretty console
|
|
18
|
-
* //
|
|
16
|
+
* // setupRuntime identifies the service (name+version are REQUIRED inputs) and installs the backend:
|
|
17
|
+
* // setupRuntime(new RuntimeSetupOptions('my-service', '2.1.0', loggerFactory, ...))
|
|
19
18
|
* ```
|
|
20
19
|
*
|
|
20
|
+
* (svcName rides winston `defaultMeta`, read at factory CONSTRUCTION — so if you need it on winston
|
|
21
|
+
* lines, call `ServiceInfo.setInfo('my-service', '2.1.0')` before building the factory too; `version`
|
|
22
|
+
* is stamped per-record and appears the moment setupRuntime runs regardless of construction order.)
|
|
23
|
+
*
|
|
21
24
|
* BREAKING (was `new WinstonFactoryOptions(svcGitHash)` passed to each factory): the version moved
|
|
22
25
|
* to `ServiceInfo.setInfo(name, version)` in @webpieces/core-util, because it is a fact about the
|
|
23
26
|
* SERVICE, not about winston — bunyan needs the same version and previously could not stamp one at
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/index.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAC1B,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,iDAAkE;AAAzD,8GAAA,aAAa,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AACxC,mCAMkB;AALd,2GAAA,iBAAiB,OAAA;AACjB,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AACd,2GAAA,iBAAiB,OAAA","sourcesContent":["/**\n * @webpieces/winston\n *\n * Node-only winston {@link LoggerFactory} backends for webpieces. Install one at\n * startup via `LogManager.setFactory(...)`:\n *\n * ```ts\n * import { WinstonGcpFactory, WinstonConsoleFactory } from '@webpieces/winston';\n *\n * const loggerFactory = process.env.K_SERVICE\n * ? new WinstonGcpFactory() // Cloud Run → stdout JSON\n * : new WinstonConsoleFactory(); // local → pretty console\n * // setupRuntime identifies the service (name+version are REQUIRED inputs) and installs the backend:\n * // setupRuntime(new RuntimeSetupOptions('my-service', '2.1.0', loggerFactory, ...))\n * ```\n *\n * (svcName rides winston `defaultMeta`, read at factory CONSTRUCTION — so if you need it on winston\n * lines, call `ServiceInfo.setInfo('my-service', '2.1.0')` before building the factory too; `version`\n * is stamped per-record and appears the moment setupRuntime runs regardless of construction order.)\n *\n * BREAKING (was `new WinstonFactoryOptions(svcGitHash)` passed to each factory): the version moved\n * to `ServiceInfo.setInfo(name, version)` in @webpieces/core-util, because it is a fact about the\n * SERVICE, not about winston — bunyan needs the same version and previously could not stamp one at\n * all. It is also no longer presumed to be a git SHA: `version` is opaque, so a project deploying\n * semver or CI build numbers is no longer misdescribed. Migration: delete the `WinstonFactoryOptions`\n * import, call `ServiceInfo.setInfo(<name>, <the same hash>)` before building the factory, and drop\n * the ctor argument. A forgotten call throws at startup. Note the field renamed `svcGitHash` →\n * `version`, so GCP log filters/alerts on `jsonPayload.svcGitHash` must be updated.\n *\n * Both backends auto-enrich every line with the logged context keys, read\n * DIRECTLY from the active RequestContext (@webpieces/core-context) on each line —\n * no ContextReader is threaded in. Every line also carries `svcName` + `version` from ServiceInfo,\n * though neither renders in the LOCAL pretty format (you know your own service, and can check git).\n *\n * @packageDocumentation\n */\nexport { WinstonGcpFactory } from './WinstonGcpFactory';\nexport { WinstonConsoleFactory } from './WinstonConsoleFactory';\nexport { ChunkingConsoleTransport } from './ChunkingConsoleTransport';\nexport { WinstonLogger, LEVEL_TO_WINSTON } from './WinstonLogger';\nexport {\n LEVEL_TO_SEVERITY,\n bigIntSafeFormat,\n injectContextFormat,\n severityFormat,\n localPrettyFormat,\n} from './format';\n"]}
|