@webpieces/winston 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/winston",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.400",
|
|
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.400",
|
|
27
|
+
"@webpieces/core-context": "0.4.400",
|
|
28
28
|
"winston": "3.11.0",
|
|
29
29
|
"logform": "2.7.0",
|
|
30
30
|
"safe-stable-stringify": "2.5.0"
|
|
@@ -8,12 +8,14 @@ import type { Logger, LoggerFactory } from '@webpieces/core-util';
|
|
|
8
8
|
* out a cached {@link WinstonLogger} per name (each a winston child carrying
|
|
9
9
|
* `loggerName`). Subclasses differ only in the format stack they pass up.
|
|
10
10
|
*
|
|
11
|
-
* Every line carries `svcName`
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Every line carries `svcName` from {@link ServiceInfo} (winston has no mandatory logger name, so this
|
|
12
|
+
* backend used to emit none — a winston service was distinguishable only by GCP's own resource
|
|
13
|
+
* labels). It is read here at construction and rides as `defaultMeta`; it is simply absent if the
|
|
14
|
+
* service was not identified before this factory was built.
|
|
15
|
+
*
|
|
16
|
+
* `version` is NOT read here: it is stamped per-record by `RequestContext.buildStructuredLogFields`
|
|
17
|
+
* (the one map `injectContextFormat` already loops), so it appears the moment `setInfo` runs — even
|
|
18
|
+
* if that is after this factory was constructed — and logging works before it.
|
|
17
19
|
*/
|
|
18
20
|
export declare abstract class WinstonFactoryBase implements LoggerFactory {
|
|
19
21
|
private readonly base;
|
|
@@ -11,12 +11,14 @@ const WinstonLogger_1 = require("./WinstonLogger");
|
|
|
11
11
|
* out a cached {@link WinstonLogger} per name (each a winston child carrying
|
|
12
12
|
* `loggerName`). Subclasses differ only in the format stack they pass up.
|
|
13
13
|
*
|
|
14
|
-
* Every line carries `svcName`
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* Every line carries `svcName` from {@link ServiceInfo} (winston has no mandatory logger name, so this
|
|
15
|
+
* backend used to emit none — a winston service was distinguishable only by GCP's own resource
|
|
16
|
+
* labels). It is read here at construction and rides as `defaultMeta`; it is simply absent if the
|
|
17
|
+
* service was not identified before this factory was built.
|
|
18
|
+
*
|
|
19
|
+
* `version` is NOT read here: it is stamped per-record by `RequestContext.buildStructuredLogFields`
|
|
20
|
+
* (the one map `injectContextFormat` already loops), so it appears the moment `setInfo` runs — even
|
|
21
|
+
* if that is after this factory was constructed — and logging works before it.
|
|
20
22
|
*/
|
|
21
23
|
class WinstonFactoryBase {
|
|
22
24
|
base;
|
|
@@ -28,12 +30,14 @@ class WinstonFactoryBase {
|
|
|
28
30
|
* about the SINK, which is where it actually lives — a dev terminal has no such limit.
|
|
29
31
|
*/
|
|
30
32
|
constructor(finalFormat, transport) {
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// svcName is a base field on every record when known. Non-throwing read: if the service was
|
|
34
|
+
// not identified before this factory was built, svcName is simply omitted rather than blocking
|
|
35
|
+
// the deploy — setupRuntime enforces identity separately via ServiceInfo.assertIdentified().
|
|
36
|
+
const svcName = core_util_1.ServiceInfo.getName();
|
|
37
|
+
const defaultMeta = {};
|
|
38
|
+
if (svcName) {
|
|
39
|
+
defaultMeta['svcName'] = svcName;
|
|
40
|
+
}
|
|
37
41
|
// No level set — we do NOT filter; that is winston's job (defaults to 'info').
|
|
38
42
|
this.base = (0, winston_1.createLogger)({
|
|
39
43
|
format: finalFormat,
|
|
@@ -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
|
|
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;AAtCD,gDAsCC","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 enforces identity separately via ServiceInfo.assertIdentified().\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"]}
|