@polygonlabs/logger 1.0.1 → 2.0.0
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/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +61 -24
- package/dist/logger.js.map +1 -1
- package/package.json +8 -4
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAMrE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAMD,wBAAsB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAMrE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAMD,wBAAsB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmJjF"}
|
package/dist/logger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pino, stdSerializers } from 'pino';
|
|
2
|
-
import { VError,
|
|
2
|
+
import { VError, WERROR_SYMBOL } from '@polygonlabs/verror';
|
|
3
3
|
// Pino's numeric level for "error". Levels at or above this (error=50, fatal=60)
|
|
4
4
|
// are captured in Sentry.
|
|
5
5
|
const PINO_ERROR_LEVEL = 50;
|
|
@@ -26,34 +26,68 @@ export async function createLogger(options) {
|
|
|
26
26
|
},
|
|
27
27
|
log(object) {
|
|
28
28
|
let out = object;
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
// Reserved keys — values that the logger or Datadog agent writes
|
|
30
|
+
// authoritatively. If a caller includes one of these in a merge object it
|
|
31
|
+
// either silently overrides the authoritative value or is silently dropped.
|
|
32
|
+
//
|
|
33
|
+
// Strategy: collect all caller-supplied reserved values into a single
|
|
34
|
+
// nested `_logger` object. Using a namespace rather than flat renamed keys
|
|
35
|
+
// (e.g. `callerTimestamp`) avoids a second collision surface — `_logger`
|
|
36
|
+
// is far less likely to be used by application code than `callerFoo`.
|
|
37
|
+
//
|
|
38
|
+
// If `_logger` itself is in the merge object we merge into it (preserving
|
|
39
|
+
// whatever the caller put there) and emit a warn, rather than clobbering.
|
|
40
|
+
//
|
|
41
|
+
// Reserved keys and why:
|
|
42
|
+
// timestamp — written by the pino timestamp function; caller value
|
|
43
|
+
// would shadow the authoritative ISO 8601 string
|
|
44
|
+
// message — written by pino as messageKey; caller value in the merge
|
|
45
|
+
// object races with the string argument
|
|
46
|
+
// service — set by the Datadog agent from the container name; a
|
|
47
|
+
// caller value silently breaks log attribution
|
|
48
|
+
// host — set by the Datadog agent from the container hostname; a
|
|
49
|
+
// caller value silently overrides infrastructure routing
|
|
50
|
+
const RESERVED = ['timestamp', 'message', 'service', 'host'];
|
|
51
|
+
const shadowed = {};
|
|
52
|
+
for (const key of RESERVED) {
|
|
53
|
+
if (key in out) {
|
|
54
|
+
shadowed[key] = out[key];
|
|
55
|
+
const { [key]: _dropped, ...rest } = out;
|
|
56
|
+
out = rest;
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
59
|
+
if (Object.keys(shadowed).length > 0) {
|
|
60
|
+
// Merge into any existing _logger value rather than clobber it.
|
|
61
|
+
const existing = typeof out['_logger'] === 'object' && out['_logger'] !== null
|
|
62
|
+
? out['_logger']
|
|
63
|
+
: {};
|
|
64
|
+
if ('_logger' in out && (typeof out['_logger'] !== 'object' || out['_logger'] === null)) {
|
|
65
|
+
// _logger exists but is a primitive — warn separately so it isn't lost.
|
|
66
|
+
ref.self?.warn({ _logger: out['_logger'] }, 'Log call included "_logger" as a non-object — overwritten by logger internals. Fix the call site.');
|
|
67
|
+
}
|
|
68
|
+
out = { ...out, _logger: { ...existing, ...shadowed } };
|
|
69
|
+
const keys = Object.keys(shadowed).join(', ');
|
|
70
|
+
ref.self?.warn({ _logger: shadowed }, `Log call included reserved key(s) [${keys}] in merge object — moved to _logger. Fix the call site.`);
|
|
51
71
|
}
|
|
52
72
|
return out;
|
|
53
73
|
}
|
|
54
74
|
},
|
|
55
75
|
serializers: {
|
|
56
|
-
err
|
|
76
|
+
// Extend pino's standard err serializer with VError's merged info chain.
|
|
77
|
+
// VError.info() walks the full cause chain and merges info from all links,
|
|
78
|
+
// whereas stdSerializers.err only captures the top-level error's own .info.
|
|
79
|
+
// We replace the base .info with the merged chain (omitting the key entirely
|
|
80
|
+
// when the chain has no info) so callers always get the full context.
|
|
81
|
+
// VError.info() duck-types .info so it works across module boundaries.
|
|
82
|
+
err(err) {
|
|
83
|
+
const base = stdSerializers.err(err);
|
|
84
|
+
if (err instanceof Error) {
|
|
85
|
+
const merged = VError.info(err);
|
|
86
|
+
const { info: _dropped, ...rest } = base;
|
|
87
|
+
return Object.keys(merged).length > 0 ? { ...rest, info: merged } : rest;
|
|
88
|
+
}
|
|
89
|
+
return base;
|
|
90
|
+
}
|
|
57
91
|
},
|
|
58
92
|
hooks: {
|
|
59
93
|
logMethod(args, method, level) {
|
|
@@ -62,8 +96,11 @@ export async function createLogger(options) {
|
|
|
62
96
|
const obj = first;
|
|
63
97
|
if (obj['err'] instanceof Error) {
|
|
64
98
|
// Unwrap WError chain — WError's own message is never the useful signal.
|
|
99
|
+
// Use WERROR_SYMBOL (Symbol.for) instead of instanceof — works across
|
|
100
|
+
// module boundaries regardless of how many copies of @polygonlabs/verror
|
|
101
|
+
// are loaded.
|
|
65
102
|
let err = obj['err'];
|
|
66
|
-
while (err
|
|
103
|
+
while (err[WERROR_SYMBOL] === true) {
|
|
67
104
|
const cause = VError.cause(err);
|
|
68
105
|
if (cause === null)
|
|
69
106
|
break;
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,aAAa,E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BACd,CAAC;wBACD,IAAI,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;4BAAG,IAAkB,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC;wBAEjE,yCAAyC;wBACzC,IAAI,KAAK,IAAI,gBAAgB;4BAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;oBACxE,CAAC;gBACH,CAAC;gBACD,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3B,CAAC;SACF;KACF,CAAC;IAEF,IAAI,WAAW,GAAkC,OAAO,EAAE,WAAW,CAAC;IACtE,IAAI,CAAC,WAAW,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,WAAW,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC;gBAClD,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,WAAW;gBACzB,aAAa,EAAE,cAAc;gBAC7B,MAAM,EAAE,cAAc;gBACtB,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,IAAI,CACV,sHAAsH,CACvH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE9E,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polygonlabs/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Pino-based logger with Sentry integration, configured for Datadog ingestion and prettified output capable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"MIGRATION.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"pino": "^10.3.1"
|
|
26
|
-
"@polygonlabs/verror": "1.0.1"
|
|
25
|
+
"pino": "^10.3.1"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@tsconfig/node-ts": "^23.0.0",
|
|
@@ -31,13 +30,18 @@
|
|
|
31
30
|
"@types/node": "^24.0.0",
|
|
32
31
|
"pino-pretty": "^13.1.3",
|
|
33
32
|
"typescript": "^5.9.3",
|
|
34
|
-
"vitest": "^3.2.3"
|
|
33
|
+
"vitest": "^3.2.3",
|
|
34
|
+
"@polygonlabs/verror": "1.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
+
"@polygonlabs/verror": ">=1.0.2",
|
|
37
38
|
"@sentry/node": ">=8.0.0",
|
|
38
39
|
"pino-pretty": ">=13.0.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependenciesMeta": {
|
|
42
|
+
"@polygonlabs/verror": {
|
|
43
|
+
"optional": false
|
|
44
|
+
},
|
|
41
45
|
"@sentry/node": {
|
|
42
46
|
"optional": true
|
|
43
47
|
},
|