@polygonlabs/logger 1.0.0 → 1.0.2
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/MIGRATION.md +48 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +55 -20
- package/dist/logger.js.map +1 -1
- package/package.json +4 -3
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
## 0.2 → 0.3
|
|
4
|
+
|
|
5
|
+
### Replace `logError()` with standard pino log methods
|
|
6
|
+
|
|
7
|
+
`logError()` has been removed. VError and WError handling is now automatic for
|
|
8
|
+
every standard pino log level, so the dedicated method is no longer needed.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// before
|
|
12
|
+
logger.logError({ err });
|
|
13
|
+
logger.logError({ err, requestId }, 'optional message');
|
|
14
|
+
|
|
15
|
+
// after
|
|
16
|
+
logger.error({ err }, err.message);
|
|
17
|
+
logger.error({ err, requestId }, 'optional message');
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
WError unwrapping, `error_info` emission, and Sentry capture all happen
|
|
21
|
+
automatically on `logger.error({ err })` calls — no special method required.
|
|
22
|
+
|
|
23
|
+
> **Note:** `error_info` is a reserved key written by the logger. Do not include
|
|
24
|
+
> it in merge objects passed to any log method. If a caller supplies it, the logger
|
|
25
|
+
> emits a `warn`-level entry with the conflicting value under `callerErrorInfo`
|
|
26
|
+
> and overwrites the key with the real VError info.
|
|
27
|
+
|
|
28
|
+
### Replace `AppLogger` with pino's `Logger` type
|
|
29
|
+
|
|
30
|
+
`createLogger` now returns pino's `Logger` directly. If your service declared
|
|
31
|
+
`AppLogger` as a parameter or field type, update it to `Logger` from `pino`.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// before
|
|
35
|
+
import { createLogger, AppLogger } from '@polygonlabs/logger';
|
|
36
|
+
|
|
37
|
+
class MyService {
|
|
38
|
+
constructor(private logger: AppLogger) {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// after
|
|
42
|
+
import { createLogger } from '@polygonlabs/logger';
|
|
43
|
+
import type { Logger } from 'pino';
|
|
44
|
+
|
|
45
|
+
class MyService {
|
|
46
|
+
constructor(private logger: Logger) {}
|
|
47
|
+
}
|
|
48
|
+
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC"}
|
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,CA4IjF"}
|
package/dist/logger.js
CHANGED
|
@@ -26,20 +26,50 @@ export async function createLogger(options) {
|
|
|
26
26
|
},
|
|
27
27
|
log(object) {
|
|
28
28
|
let out = object;
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
// error_info — written by formatters.log from VError.info(); caller
|
|
47
|
+
// value would be overwritten without warning
|
|
48
|
+
// service — set by the Datadog agent from the container name; a
|
|
49
|
+
// caller value silently breaks log attribution
|
|
50
|
+
// host — set by the Datadog agent from the container hostname; a
|
|
51
|
+
// caller value silently overrides infrastructure routing
|
|
52
|
+
const RESERVED = ['timestamp', 'message', 'error_info', 'service', 'host'];
|
|
53
|
+
const shadowed = {};
|
|
54
|
+
for (const key of RESERVED) {
|
|
55
|
+
if (key in out) {
|
|
56
|
+
shadowed[key] = out[key];
|
|
57
|
+
const { [key]: _dropped, ...rest } = out;
|
|
58
|
+
out = rest;
|
|
59
|
+
}
|
|
35
60
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
if (Object.keys(shadowed).length > 0) {
|
|
62
|
+
// Merge into any existing _logger value rather than clobber it.
|
|
63
|
+
const existing = typeof out['_logger'] === 'object' && out['_logger'] !== null
|
|
64
|
+
? out['_logger']
|
|
65
|
+
: {};
|
|
66
|
+
if ('_logger' in out && (typeof out['_logger'] !== 'object' || out['_logger'] === null)) {
|
|
67
|
+
// _logger exists but is a primitive — warn separately so it isn't lost.
|
|
68
|
+
ref.self?.warn({ _logger: out['_logger'] }, 'Log call included "_logger" as a non-object — overwritten by logger internals. Fix the call site.');
|
|
69
|
+
}
|
|
70
|
+
out = { ...out, _logger: { ...existing, ...shadowed } };
|
|
71
|
+
const keys = Object.keys(shadowed).join(', ');
|
|
72
|
+
ref.self?.warn({ _logger: shadowed }, `Log call included reserved key(s) [${keys}] in merge object — moved to _logger. Fix the call site.`);
|
|
43
73
|
}
|
|
44
74
|
// Emit merged VError info chain under error_info for structured querying.
|
|
45
75
|
// By this point hooks.logMethod has already unwrapped any WError, so err
|
|
@@ -82,13 +112,18 @@ export async function createLogger(options) {
|
|
|
82
112
|
};
|
|
83
113
|
let destination = options?.destination;
|
|
84
114
|
if (!destination && options?.pretty) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
try {
|
|
116
|
+
destination = (await import('pino-pretty')).default({
|
|
117
|
+
colorize: true,
|
|
118
|
+
timestampKey: 'timestamp',
|
|
119
|
+
translateTime: 'SYS:standard',
|
|
120
|
+
ignore: 'pid,hostname',
|
|
121
|
+
sync: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
console.warn('pino-pretty is not installed — falling back to JSON output. Install it as a dev dependency to enable pretty logging.');
|
|
126
|
+
}
|
|
92
127
|
}
|
|
93
128
|
const base = destination ? pino(pinoOptions, destination) : pino(pinoOptions);
|
|
94
129
|
ref.self = base;
|
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,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA4BrD,iFAAiF;AACjF,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAA6B;IAC9D,4EAA4E;IAC5E,+EAA+E;IAC/E,kEAA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M,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": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Pino-based logger with Sentry integration, configured for Datadog ingestion and prettified output capable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
-
"dist"
|
|
21
|
+
"dist",
|
|
22
|
+
"MIGRATION.md"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"pino": "^10.3.1",
|
|
25
|
-
"@polygonlabs/verror": "1.0.
|
|
26
|
+
"@polygonlabs/verror": "1.0.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@tsconfig/node-ts": "^23.0.0",
|