@polygonlabs/logger 0.3.0 → 1.0.1
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 +3 -3
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +22 -12
- package/dist/logger.js.map +1 -1
- package/package.json +5 -4
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
CHANGED
|
@@ -17,9 +17,9 @@ export interface CreateLoggerOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
destination?: DestinationStream;
|
|
19
19
|
/**
|
|
20
|
-
* Optional Sentry adapter for automatic error capturing on logger.error()
|
|
21
|
-
* Pass your initialised @sentry/node instance (or any
|
|
22
|
-
* SentryAdapter). Inherited by all child loggers.
|
|
20
|
+
* Optional Sentry adapter for automatic error capturing on logger.error() and
|
|
21
|
+
* logger.fatal() calls. Pass your initialised @sentry/node instance (or any
|
|
22
|
+
* object satisfying SentryAdapter). Inherited by all child loggers.
|
|
23
23
|
*/
|
|
24
24
|
sentry?: SentryAdapter;
|
|
25
25
|
}
|
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;
|
|
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,CA2GjF"}
|
package/dist/logger.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { pino, stdSerializers } from 'pino';
|
|
2
2
|
import { VError, WError } from '@polygonlabs/verror';
|
|
3
|
-
// Pino's numeric level for "error".
|
|
3
|
+
// Pino's numeric level for "error". Levels at or above this (error=50, fatal=60)
|
|
4
|
+
// are captured in Sentry.
|
|
4
5
|
const PINO_ERROR_LEVEL = 50;
|
|
5
6
|
export async function createLogger(options) {
|
|
6
7
|
// ref.self is assigned immediately after pino() returns. The formatters.log
|
|
@@ -62,12 +63,16 @@ export async function createLogger(options) {
|
|
|
62
63
|
if (obj['err'] instanceof Error) {
|
|
63
64
|
// Unwrap WError chain — WError's own message is never the useful signal.
|
|
64
65
|
let err = obj['err'];
|
|
65
|
-
while (err instanceof WError)
|
|
66
|
-
|
|
66
|
+
while (err instanceof WError) {
|
|
67
|
+
const cause = VError.cause(err);
|
|
68
|
+
if (cause === null)
|
|
69
|
+
break;
|
|
70
|
+
err = cause;
|
|
71
|
+
}
|
|
67
72
|
if (err !== obj['err'])
|
|
68
73
|
args[0] = { ...obj, err };
|
|
69
|
-
// Capture in Sentry for error
|
|
70
|
-
if (level
|
|
74
|
+
// Capture in Sentry for error and fatal.
|
|
75
|
+
if (level >= PINO_ERROR_LEVEL)
|
|
71
76
|
options?.sentry?.captureException(err);
|
|
72
77
|
}
|
|
73
78
|
}
|
|
@@ -77,13 +82,18 @@ export async function createLogger(options) {
|
|
|
77
82
|
};
|
|
78
83
|
let destination = options?.destination;
|
|
79
84
|
if (!destination && options?.pretty) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
try {
|
|
86
|
+
destination = (await import('pino-pretty')).default({
|
|
87
|
+
colorize: true,
|
|
88
|
+
timestampKey: 'timestamp',
|
|
89
|
+
translateTime: 'SYS:standard',
|
|
90
|
+
ignore: 'pid,hostname',
|
|
91
|
+
sync: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
console.warn('pino-pretty is not installed — falling back to JSON output. Install it as a dev dependency to enable pretty logging.');
|
|
96
|
+
}
|
|
87
97
|
}
|
|
88
98
|
const base = destination ? pino(pinoOptions, destination) : pino(pinoOptions);
|
|
89
99
|
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,
|
|
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,kEAAkE;IAClE,MAAM,GAAG,GAAiC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAE9D,MAAM,WAAW,GAAkB;QACjC,KAAK,EAAE,OAAO;QACd,sEAAsE;QACtE,UAAU,EAAE,SAAS;QACrB,mDAAmD;QACnD,IAAI,EAAE,SAAS;QACf,iEAAiE;QACjE,2EAA2E;QAC3E,6EAA6E;QAC7E,eAAe;QACf,SAAS,EAAE,GAAG,EAAE,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,GAAG;QAC7D,UAAU,EAAE;YACV,oEAAoE;YACpE,KAAK,CAAC,KAAa;gBACjB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YAC1B,CAAC;YACD,GAAG,CAAC,MA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O,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": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
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": "0.
|
|
26
|
+
"@polygonlabs/verror": "1.0.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@tsconfig/node-ts": "^23.0.0",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
|
-
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"build": "pnpm run typecheck && tsc -p tsconfig.build.json",
|
|
49
50
|
"typecheck": "tsc --noEmit",
|
|
50
51
|
"test": "vitest run",
|
|
51
52
|
"lint": "eslint .",
|