nestjs-pino 3.1.1-alpha.fa0037 → 3.1.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/LoggerModule.js +17 -18
- package/PinoLogger.d.ts +1 -1
- package/package.json +2 -2
- package/params.d.ts +1 -1
package/LoggerModule.js
CHANGED
|
@@ -23,9 +23,6 @@ const InjectPinoLogger_1 = require("./InjectPinoLogger");
|
|
|
23
23
|
const storage_1 = require("./storage");
|
|
24
24
|
const DEFAULT_ROUTES = [{ path: '*', method: common_1.RequestMethod.ALL }];
|
|
25
25
|
let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
26
|
-
constructor(params) {
|
|
27
|
-
this.params = params;
|
|
28
|
-
}
|
|
29
26
|
static forRoot(params) {
|
|
30
27
|
const paramsProvider = {
|
|
31
28
|
provide: params_1.PARAMS_PROVIDER_TOKEN,
|
|
@@ -59,6 +56,9 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
|
59
56
|
exports: [Logger_1.Logger, ...decorated, PinoLogger_1.PinoLogger, paramsProvider],
|
|
60
57
|
};
|
|
61
58
|
}
|
|
59
|
+
constructor(params) {
|
|
60
|
+
this.params = params;
|
|
61
|
+
}
|
|
62
62
|
configure(consumer) {
|
|
63
63
|
const { exclude, forRoutes = DEFAULT_ROUTES, pinoHttp, useExisting, } = this.params;
|
|
64
64
|
const middlewares = createLoggerMiddlewares(pinoHttp || {}, useExisting);
|
|
@@ -80,28 +80,27 @@ LoggerModule = LoggerModule_1 = __decorate([
|
|
|
80
80
|
__metadata("design:paramtypes", [Object])
|
|
81
81
|
], LoggerModule);
|
|
82
82
|
exports.LoggerModule = LoggerModule;
|
|
83
|
-
function createLoggerMiddlewares(params, useExisting) {
|
|
83
|
+
function createLoggerMiddlewares(params, useExisting = false) {
|
|
84
84
|
if (useExisting) {
|
|
85
|
-
return [
|
|
85
|
+
return [bindLoggerMiddlewareFactory(useExisting)];
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
const middleware = (0, pino_http_1.pinoHttp)(...params);
|
|
89
|
-
// @ts-expect-error: root is readonly field, but this is the place where
|
|
90
|
-
// it's set actually
|
|
91
|
-
PinoLogger_1.PinoLogger.root = middleware.logger;
|
|
92
|
-
return [middleware, bindLoggerMiddleware];
|
|
93
|
-
}
|
|
94
|
-
const middleware = (0, pino_http_1.pinoHttp)(params);
|
|
87
|
+
const middleware = (0, pino_http_1.pinoHttp)(...(Array.isArray(params) ? params : [params]));
|
|
95
88
|
// @ts-expect-error: root is readonly field, but this is the place where
|
|
96
89
|
// it's set actually
|
|
97
90
|
PinoLogger_1.PinoLogger.root = middleware.logger;
|
|
98
91
|
// FIXME: params type here is pinoHttp.Options | pino.DestinationStream
|
|
99
92
|
// pinoHttp has two overloads, each of them takes those types
|
|
100
|
-
return [middleware,
|
|
93
|
+
return [middleware, bindLoggerMiddlewareFactory(useExisting)];
|
|
101
94
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
function bindLoggerMiddlewareFactory(useExisting) {
|
|
96
|
+
return function bindLoggerMiddleware(req, _res, next) {
|
|
97
|
+
let log = req.log;
|
|
98
|
+
if (!useExisting && req.allLogs) {
|
|
99
|
+
log = req.allLogs[req.allLogs.length - 1];
|
|
100
|
+
}
|
|
101
|
+
// @ts-ignore: run requires arguments for next but should not because it can
|
|
102
|
+
// be called without arguments
|
|
103
|
+
storage_1.storage.run(new storage_1.Store(log), next);
|
|
104
|
+
};
|
|
106
105
|
}
|
|
107
106
|
//# sourceMappingURL=LoggerModule.js.map
|
package/PinoLogger.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
2
|
import { Params } from './params';
|
|
3
|
-
|
|
3
|
+
type PinoMethods = Pick<pino.Logger, 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'>;
|
|
4
4
|
export declare function __resetOutOfContextForTests(): void;
|
|
5
5
|
export declare class PinoLogger implements PinoMethods {
|
|
6
6
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-pino",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Pino logger for NestJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"jest": "27.5.1",
|
|
59
59
|
"memorystream": "^0.3.1",
|
|
60
60
|
"pino": "^8.2.0",
|
|
61
|
-
"pino-http": "^8.
|
|
61
|
+
"pino-http": "^8.3.1",
|
|
62
62
|
"prettier": "^2.3.2",
|
|
63
63
|
"reflect-metadata": "^0.1.13",
|
|
64
64
|
"rimraf": "^3.0.2",
|
package/params.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Options } from 'pino-http';
|
|
2
2
|
import { Logger, DestinationStream } from 'pino';
|
|
3
3
|
import { MiddlewareConfigProxy, ModuleMetadata } from '@nestjs/common/interfaces';
|
|
4
|
-
export
|
|
4
|
+
export type PassedLogger = {
|
|
5
5
|
logger: Logger;
|
|
6
6
|
};
|
|
7
7
|
export interface Params {
|