nestjs-pino 3.3.0 → 3.4.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/Logger.d.ts +2 -1
- package/Logger.js +5 -1
- package/LoggerErrorInterceptor.js +1 -0
- package/LoggerModule.js +3 -1
- package/PinoLogger.d.ts +2 -2
- package/PinoLogger.js +16 -13
- package/README.md +18 -11
- package/package.json +27 -42
- package/params.d.ts +2 -2
package/Logger.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LoggerService } from '@nestjs/common';
|
|
2
|
-
import { PinoLogger } from './PinoLogger';
|
|
3
2
|
import { Params } from './params';
|
|
3
|
+
import { PinoLogger } from './PinoLogger';
|
|
4
4
|
export declare class Logger implements LoggerService {
|
|
5
5
|
protected readonly logger: PinoLogger;
|
|
6
6
|
private readonly contextName;
|
|
@@ -10,6 +10,7 @@ export declare class Logger implements LoggerService {
|
|
|
10
10
|
log(message: any, ...optionalParams: any[]): void;
|
|
11
11
|
warn(message: any, ...optionalParams: any[]): void;
|
|
12
12
|
error(message: any, ...optionalParams: any[]): void;
|
|
13
|
+
fatal(message: any, ...optionalParams: any[]): void;
|
|
13
14
|
private call;
|
|
14
15
|
/**
|
|
15
16
|
* Unfortunately built-in (not only) `^.*Exception(s?)Handler$` classes call `.error`
|
package/Logger.js
CHANGED
|
@@ -13,9 +13,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Logger = void 0;
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
16
17
|
const common_1 = require("@nestjs/common");
|
|
17
|
-
const PinoLogger_1 = require("./PinoLogger");
|
|
18
18
|
const params_1 = require("./params");
|
|
19
|
+
const PinoLogger_1 = require("./PinoLogger");
|
|
19
20
|
let Logger = exports.Logger = class Logger {
|
|
20
21
|
constructor(logger, { renameContext }) {
|
|
21
22
|
this.logger = logger;
|
|
@@ -36,6 +37,9 @@ let Logger = exports.Logger = class Logger {
|
|
|
36
37
|
error(message, ...optionalParams) {
|
|
37
38
|
this.call('error', message, ...optionalParams);
|
|
38
39
|
}
|
|
40
|
+
fatal(message, ...optionalParams) {
|
|
41
|
+
this.call('fatal', message, ...optionalParams);
|
|
42
|
+
}
|
|
39
43
|
call(level, message, ...optionalParams) {
|
|
40
44
|
const objArg = {};
|
|
41
45
|
// optionalParams contains extra params passed to logger
|
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.LoggerErrorInterceptor = void 0;
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
11
|
const common_1 = require("@nestjs/common");
|
|
11
12
|
const rxjs_1 = require("rxjs");
|
|
12
13
|
let LoggerErrorInterceptor = exports.LoggerErrorInterceptor = class LoggerErrorInterceptor {
|
package/LoggerModule.js
CHANGED
|
@@ -14,12 +14,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
var LoggerModule_1;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.LoggerModule = void 0;
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
18
|
const common_1 = require("@nestjs/common");
|
|
18
19
|
const pino_http_1 = require("pino-http");
|
|
20
|
+
const InjectPinoLogger_1 = require("./InjectPinoLogger");
|
|
19
21
|
const Logger_1 = require("./Logger");
|
|
20
22
|
const params_1 = require("./params");
|
|
21
23
|
const PinoLogger_1 = require("./PinoLogger");
|
|
22
|
-
const InjectPinoLogger_1 = require("./InjectPinoLogger");
|
|
23
24
|
const storage_1 = require("./storage");
|
|
24
25
|
const DEFAULT_ROUTES = [{ path: '*', method: common_1.RequestMethod.ALL }];
|
|
25
26
|
let LoggerModule = exports.LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
@@ -97,6 +98,7 @@ function bindLoggerMiddlewareFactory(useExisting) {
|
|
|
97
98
|
if (!useExisting && req.allLogs) {
|
|
98
99
|
log = req.allLogs[req.allLogs.length - 1];
|
|
99
100
|
}
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
100
102
|
// @ts-ignore: run requires arguments for next but should not because it can
|
|
101
103
|
// be called without arguments
|
|
102
104
|
storage_1.storage.run(new storage_1.Store(log), next);
|
package/PinoLogger.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare class PinoLogger implements PinoMethods {
|
|
|
26
26
|
protected context: string;
|
|
27
27
|
protected readonly contextName: string;
|
|
28
28
|
constructor({ pinoHttp, renameContext }: Params);
|
|
29
|
+
get logger(): pino.Logger;
|
|
29
30
|
trace(msg: string, ...args: any[]): void;
|
|
30
31
|
trace(obj: unknown, msg?: string, ...args: any[]): void;
|
|
31
32
|
debug(msg: string, ...args: any[]): void;
|
|
@@ -39,8 +40,7 @@ export declare class PinoLogger implements PinoMethods {
|
|
|
39
40
|
fatal(msg: string, ...args: any[]): void;
|
|
40
41
|
fatal(obj: unknown, msg?: string, ...args: any[]): void;
|
|
41
42
|
setContext(value: string): void;
|
|
42
|
-
protected call(method: pino.Level, ...args: Parameters<LoggerFn>): void;
|
|
43
|
-
get logger(): pino.Logger;
|
|
44
43
|
assign(fields: pino.Bindings): void;
|
|
44
|
+
protected call(method: pino.Level, ...args: Parameters<LoggerFn>): void;
|
|
45
45
|
}
|
|
46
46
|
export {};
|
package/PinoLogger.js
CHANGED
|
@@ -14,6 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
var PinoLogger_1;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.PinoLogger = exports.__resetOutOfContextForTests = void 0;
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
18
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
18
19
|
const common_1 = require("@nestjs/common");
|
|
19
20
|
const pino_1 = require("pino");
|
|
@@ -22,6 +23,7 @@ const storage_1 = require("./storage");
|
|
|
22
23
|
let outOfContext;
|
|
23
24
|
function __resetOutOfContextForTests() {
|
|
24
25
|
outOfContext = undefined;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
27
|
// @ts-ignore reset root for tests only
|
|
26
28
|
PinoLogger.root = undefined;
|
|
27
29
|
}
|
|
@@ -47,6 +49,12 @@ let PinoLogger = exports.PinoLogger = PinoLogger_1 = class PinoLogger {
|
|
|
47
49
|
}
|
|
48
50
|
this.contextName = renameContext || 'context';
|
|
49
51
|
}
|
|
52
|
+
get logger() {
|
|
53
|
+
var _a;
|
|
54
|
+
// outOfContext is always set in runtime before starts using
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
56
|
+
return ((_a = storage_1.storage.getStore()) === null || _a === void 0 ? void 0 : _a.logger) || outOfContext;
|
|
57
|
+
}
|
|
50
58
|
trace(...args) {
|
|
51
59
|
this.call('trace', ...args);
|
|
52
60
|
}
|
|
@@ -68,6 +76,13 @@ let PinoLogger = exports.PinoLogger = PinoLogger_1 = class PinoLogger {
|
|
|
68
76
|
setContext(value) {
|
|
69
77
|
this.context = value;
|
|
70
78
|
}
|
|
79
|
+
assign(fields) {
|
|
80
|
+
const store = storage_1.storage.getStore();
|
|
81
|
+
if (!store) {
|
|
82
|
+
throw new Error(`${PinoLogger_1.name}: unable to assign extra fields out of request scope`);
|
|
83
|
+
}
|
|
84
|
+
store.logger = store.logger.child(fields);
|
|
85
|
+
}
|
|
71
86
|
call(method, ...args) {
|
|
72
87
|
if (this.context) {
|
|
73
88
|
if (isFirstArgObject(args)) {
|
|
@@ -89,22 +104,10 @@ let PinoLogger = exports.PinoLogger = PinoLogger_1 = class PinoLogger {
|
|
|
89
104
|
args = [{ [this.contextName]: this.context }, ...args];
|
|
90
105
|
}
|
|
91
106
|
}
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
92
108
|
// @ts-ignore args are union of tuple types
|
|
93
109
|
this.logger[method](...args);
|
|
94
110
|
}
|
|
95
|
-
get logger() {
|
|
96
|
-
var _a;
|
|
97
|
-
// outOfContext is always set in runtime before starts using
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
|
-
return ((_a = storage_1.storage.getStore()) === null || _a === void 0 ? void 0 : _a.logger) || outOfContext;
|
|
100
|
-
}
|
|
101
|
-
assign(fields) {
|
|
102
|
-
const store = storage_1.storage.getStore();
|
|
103
|
-
if (!store) {
|
|
104
|
-
throw new Error(`${PinoLogger_1.name}: unable to assign extra fields out of request scope`);
|
|
105
|
-
}
|
|
106
|
-
store.logger = store.logger.child(fields);
|
|
107
|
-
}
|
|
108
111
|
};
|
|
109
112
|
exports.PinoLogger = PinoLogger = PinoLogger_1 = __decorate([
|
|
110
113
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
package/README.md
CHANGED
|
@@ -16,15 +16,22 @@
|
|
|
16
16
|
<a href="https://www.npmjs.com/package/nestjs-pino">
|
|
17
17
|
<img alt="npm" src="https://img.shields.io/npm/v/nestjs-pino" />
|
|
18
18
|
</a>
|
|
19
|
-
<
|
|
19
|
+
<a href="https://www.npmjs.com/package/nestjs-pino">
|
|
20
|
+
<img alt="npm" src="https://img.shields.io/npm/dm/nestjs-pino" />
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://github.com/iamolegga/nestjs-pino/actions">
|
|
23
|
+
<img alt="GitHub branch checks state" src="https://badgen.net/github/checks/iamolegga/nestjs-pino">
|
|
24
|
+
</a>
|
|
20
25
|
<a href="https://codeclimate.com/github/iamolegga/nestjs-pino/test_coverage">
|
|
21
26
|
<img src="https://api.codeclimate.com/v1/badges/2821150bb93506cb66fc/test_coverage" />
|
|
22
27
|
</a>
|
|
23
28
|
<a href="https://snyk.io/test/github/iamolegga/nestjs-pino">
|
|
24
|
-
<img alt="
|
|
29
|
+
<img alt="Known Vulnerabilities" src="https://snyk.io/test/github/iamolegga/nestjs-pino/badge.svg" />
|
|
30
|
+
</a>
|
|
31
|
+
<a href="https://libraries.io/npm/nestjs-pino">
|
|
32
|
+
<img alt="Libraries.io" src="https://img.shields.io/librariesio/release/npm/nestjs-pino">
|
|
25
33
|
</a>
|
|
26
|
-
<img alt="
|
|
27
|
-
<img alt="Dependabot" src="https://badgen.net/dependabot/iamolegga/nestjs-pino/?icon=dependabot">
|
|
34
|
+
<img alt="Dependabot" src="https://badgen.net/github/dependabot/iamolegga/nestjs-pino">
|
|
28
35
|
<img alt="Supported platforms: Express & Fastify" src="https://img.shields.io/badge/platforms-Express%20%26%20Fastify-green" />
|
|
29
36
|
</p>
|
|
30
37
|
|
|
@@ -562,13 +569,13 @@ In NestJS <= 7 and `nestjs-pino@1` when you call `this.logger.log('foo', 'bar');
|
|
|
562
569
|
**A**: Pino built-in methods names are not fully compatible with NestJS built-in `LoggerService` methods names, and there is an option which logger you use. Here is methods mapping:
|
|
563
570
|
|
|
564
571
|
| `pino` method | `PinoLogger` method | NestJS built-in `Logger` method |
|
|
565
|
-
| ------------- | ------------------- |
|
|
566
|
-
| **trace** | **trace** | **verbose**
|
|
567
|
-
| debug | debug | debug
|
|
568
|
-
| **info** | **info** | **log**
|
|
569
|
-
| warn | warn | warn
|
|
570
|
-
| error | error | error
|
|
571
|
-
|
|
|
572
|
+
| ------------- | ------------------- | --------------------------------|
|
|
573
|
+
| **trace** | **trace** | **verbose** |
|
|
574
|
+
| debug | debug | debug |
|
|
575
|
+
| **info** | **info** | **log** |
|
|
576
|
+
| warn | warn | warn |
|
|
577
|
+
| error | error | error |
|
|
578
|
+
| fatal | fatal | fatal (since nestjs@10.2) |
|
|
572
579
|
|
|
573
580
|
---
|
|
574
581
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-pino",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Pino logger for NestJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jest --verbose -i --detectOpenHandles",
|
|
9
|
-
"lint": "eslint \"{src,__tests__}/**/*.ts\" --fix",
|
|
8
|
+
"test": "jest --verbose -i --detectOpenHandles --forceExit",
|
|
9
|
+
"lint": "tsc --noemit && eslint \"{src,__tests__}/**/*.ts\" --fix",
|
|
10
10
|
"prebuild": "rimraf dist",
|
|
11
11
|
"build": "tsc -p tsconfig.build.json",
|
|
12
12
|
"example": "rimraf dist && tsc && LOG_LEVEL=debug node dist/example/main",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"postinstall": "node postinstall.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"*.{js,d.ts}"
|
|
18
|
+
"*.{js,d.ts}",
|
|
19
|
+
"!jest.config.js",
|
|
20
|
+
"!.eslintrc.js"
|
|
19
21
|
],
|
|
20
22
|
"engineStrict": true,
|
|
21
23
|
"engines": {
|
|
@@ -32,59 +34,42 @@
|
|
|
32
34
|
"nest",
|
|
33
35
|
"logger"
|
|
34
36
|
],
|
|
35
|
-
"author": "
|
|
37
|
+
"author": "iamolegga <iamolegga@gmail.com> (http://github.com/iamolegga)",
|
|
36
38
|
"license": "MIT",
|
|
37
39
|
"bugs": {
|
|
38
40
|
"url": "https://github.com/iamolegga/nestjs-pino/issues"
|
|
39
41
|
},
|
|
40
42
|
"homepage": "https://github.com/iamolegga/nestjs-pino#readme",
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@nestjs/common": "^10.
|
|
43
|
-
"@nestjs/core": "^10.
|
|
44
|
-
"@nestjs/platform-express": "^10.
|
|
45
|
-
"@nestjs/platform-fastify": "^10.
|
|
46
|
-
"@nestjs/testing": "^10.
|
|
44
|
+
"@nestjs/common": "^10.2.0",
|
|
45
|
+
"@nestjs/core": "^10.2.0",
|
|
46
|
+
"@nestjs/platform-express": "^10.2.0",
|
|
47
|
+
"@nestjs/platform-fastify": "^10.2.0",
|
|
48
|
+
"@nestjs/testing": "^10.2.0",
|
|
47
49
|
"@types/express": "^4.17.17",
|
|
48
|
-
"@types/jest": "^29.5.
|
|
50
|
+
"@types/jest": "^29.5.3",
|
|
49
51
|
"@types/memorystream": "^0.3.1",
|
|
50
|
-
"@types/node": "^20.
|
|
52
|
+
"@types/node": "^20.5.1",
|
|
51
53
|
"@types/supertest": "^2.0.12",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
53
|
-
"@typescript-eslint/parser": "^
|
|
54
|
-
"eslint": "^8.
|
|
55
|
-
"eslint-config-prettier": "^
|
|
56
|
-
"eslint-plugin-import": "^2.
|
|
57
|
-
"eslint-plugin-prettier": "^
|
|
58
|
-
"jest": "29.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
55
|
+
"@typescript-eslint/parser": "^6.4.0",
|
|
56
|
+
"eslint": "^8.47.0",
|
|
57
|
+
"eslint-config-prettier": "^9.0.0",
|
|
58
|
+
"eslint-plugin-import": "^2.28.1",
|
|
59
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
60
|
+
"jest": "29.6.2",
|
|
59
61
|
"memorystream": "^0.3.1",
|
|
60
|
-
"pino": "^8.
|
|
61
|
-
"pino-http": "^8.
|
|
62
|
-
"prettier": "^
|
|
62
|
+
"pino": "^8.15.0",
|
|
63
|
+
"pino-http": "^8.4.0",
|
|
64
|
+
"prettier": "^3.0.2",
|
|
63
65
|
"reflect-metadata": "^0.1.13",
|
|
64
66
|
"rimraf": "^5.0.1",
|
|
65
67
|
"rxjs": "^7.8.1",
|
|
66
68
|
"supertest": "^6.3.3",
|
|
67
|
-
"ts-jest": "^29.1.
|
|
68
|
-
"ts-loader": "^9.4.
|
|
69
|
+
"ts-jest": "^29.1.1",
|
|
70
|
+
"ts-loader": "^9.4.4",
|
|
69
71
|
"ts-node": "^10.9.1",
|
|
70
|
-
"
|
|
71
|
-
"typescript": "^5.1.3"
|
|
72
|
-
},
|
|
73
|
-
"jest": {
|
|
74
|
-
"moduleFileExtensions": [
|
|
75
|
-
"js",
|
|
76
|
-
"ts"
|
|
77
|
-
],
|
|
78
|
-
"testRegex": ".spec.ts$",
|
|
79
|
-
"transform": {
|
|
80
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
81
|
-
},
|
|
82
|
-
"collectCoverage": true,
|
|
83
|
-
"coverageDirectory": "./coverage",
|
|
84
|
-
"collectCoverageFrom": [
|
|
85
|
-
"src/**/*.ts"
|
|
86
|
-
],
|
|
87
|
-
"testEnvironment": "node"
|
|
72
|
+
"typescript": "^5.1.6"
|
|
88
73
|
},
|
|
89
74
|
"peerDependencies": {
|
|
90
75
|
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
package/params.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Options } from 'pino-http';
|
|
2
|
-
import { Logger, DestinationStream } from 'pino';
|
|
3
1
|
import { MiddlewareConfigProxy, ModuleMetadata } from '@nestjs/common/interfaces';
|
|
2
|
+
import { Logger, DestinationStream } from 'pino';
|
|
3
|
+
import { Options } from 'pino-http';
|
|
4
4
|
export type PassedLogger = {
|
|
5
5
|
logger: Logger;
|
|
6
6
|
};
|