@webpieces/winston 0.4.393 → 0.4.394
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.394",
|
|
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.394",
|
|
27
|
+
"@webpieces/core-context": "0.4.394",
|
|
28
28
|
"winston": "3.11.0",
|
|
29
29
|
"logform": "2.7.0",
|
|
30
30
|
"safe-stable-stringify": "2.5.0"
|
|
@@ -7,6 +7,12 @@ import { WinstonFactoryOptions } from './WinstonFactoryOptions';
|
|
|
7
7
|
* handleExceptions/Rejections on) with the caller-chosen format stack, then hands
|
|
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
|
+
*
|
|
11
|
+
* Every line carries `svcName` from {@link ServiceInfo}. Winston, unlike bunyan, has
|
|
12
|
+
* NO mandatory logger name, so this backend used to emit no service name at all — a
|
|
13
|
+
* winston service was distinguishable only by GCP's own resource labels. Now both
|
|
14
|
+
* backends read the SAME {@link ServiceInfo}, so naming is a property of the service
|
|
15
|
+
* rather than of the logging library the app happened to pick.
|
|
10
16
|
*/
|
|
11
17
|
export declare abstract class WinstonFactoryBase implements LoggerFactory {
|
|
12
18
|
private readonly base;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WinstonFactoryBase = void 0;
|
|
4
4
|
const winston_1 = require("winston");
|
|
5
|
+
const core_util_1 = require("@webpieces/core-util");
|
|
5
6
|
const WinstonLogger_1 = require("./WinstonLogger");
|
|
6
7
|
/**
|
|
7
8
|
* WinstonFactoryBase - shared plumbing for the winston {@link LoggerFactory}
|
|
@@ -9,15 +10,27 @@ const WinstonLogger_1 = require("./WinstonLogger");
|
|
|
9
10
|
* handleExceptions/Rejections on) with the caller-chosen format stack, then hands
|
|
10
11
|
* out a cached {@link WinstonLogger} per name (each a winston child carrying
|
|
11
12
|
* `loggerName`). Subclasses differ only in the format stack they pass up.
|
|
13
|
+
*
|
|
14
|
+
* Every line carries `svcName` from {@link ServiceInfo}. Winston, unlike bunyan, has
|
|
15
|
+
* NO mandatory logger name, so this backend used to emit no service name at all — a
|
|
16
|
+
* winston service was distinguishable only by GCP's own resource labels. Now both
|
|
17
|
+
* backends read the SAME {@link ServiceInfo}, so naming is a property of the service
|
|
18
|
+
* rather than of the logging library the app happened to pick.
|
|
12
19
|
*/
|
|
13
20
|
class WinstonFactoryBase {
|
|
14
21
|
base;
|
|
15
22
|
loggers = new Map();
|
|
16
23
|
constructor(finalFormat, opts) {
|
|
24
|
+
// Read at STARTUP (this ctor runs while booting), so a forgotten ServiceInfo.setName(...)
|
|
25
|
+
// fails the deploy rather than shipping unnamed logs.
|
|
26
|
+
const defaultMeta = { svcName: core_util_1.ServiceInfo.getName() };
|
|
27
|
+
if (opts.svcGitHash) {
|
|
28
|
+
defaultMeta['svcGitHash'] = opts.svcGitHash;
|
|
29
|
+
}
|
|
17
30
|
// No level set — we do NOT filter; that is winston's job (defaults to 'info').
|
|
18
31
|
this.base = (0, winston_1.createLogger)({
|
|
19
32
|
format: finalFormat,
|
|
20
|
-
defaultMeta:
|
|
33
|
+
defaultMeta: defaultMeta,
|
|
21
34
|
transports: [new winston_1.transports.Console()],
|
|
22
35
|
handleExceptions: true,
|
|
23
36
|
handleRejections: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WinstonFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/WinstonFactoryBase.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAInD,mDAAgD;AAGhD
|
|
1
|
+
{"version":3,"file":"WinstonFactoryBase.js","sourceRoot":"","sources":["../../../../../packages/logging/winston/src/WinstonFactoryBase.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAInD,oDAAmD;AACnD,mDAAgD;AAGhD;;;;;;;;;;;;GAYG;AACH,MAAsB,kBAAkB;IACnB,IAAI,CAAc;IAClB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD,YAAsB,WAAmB,EAAE,IAA2B;QAClE,0FAA0F;QAC1F,sDAAsD;QACtD,MAAM,WAAW,GAA2B,EAAE,OAAO,EAAE,uBAAW,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/E,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,WAAW,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAChD,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,IAAI,oBAAU,CAAC,OAAO,EAAE,CAAC;YACtC,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;AA9BD,gDA8BC","sourcesContent":["import { createLogger, transports } from 'winston';\nimport type { Logger as WinstonBase } from 'winston';\nimport type { Format } from 'logform';\nimport type { Logger, LoggerFactory } from '@webpieces/core-util';\nimport { ServiceInfo } from '@webpieces/core-util';\nimport { WinstonLogger } from './WinstonLogger';\nimport { WinstonFactoryOptions } from './WinstonFactoryOptions';\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, unlike bunyan, has\n * NO mandatory logger name, so this backend used to emit no service name at all — a\n * winston service was distinguishable only by GCP's own resource labels. Now both\n * backends read the SAME {@link ServiceInfo}, so naming is a property of the service\n * rather than of the logging library the app happened to pick.\n */\nexport abstract class WinstonFactoryBase implements LoggerFactory {\n private readonly base: WinstonBase;\n private readonly loggers = new Map<string, Logger>();\n\n protected constructor(finalFormat: Format, opts: WinstonFactoryOptions) {\n // Read at STARTUP (this ctor runs while booting), so a forgotten ServiceInfo.setName(...)\n // fails the deploy rather than shipping unnamed logs.\n const defaultMeta: Record<string, string> = { svcName: ServiceInfo.getName() };\n if (opts.svcGitHash) {\n defaultMeta['svcGitHash'] = opts.svcGitHash;\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: [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"]}
|