nestjs-pino 3.1.1 → 3.1.2-alpha.04bd16
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/InjectPinoLogger.d.ts +1 -1
- package/LoggerModule.js +17 -18
- package/PinoLogger.d.ts +1 -1
- package/README.md +8 -3
- package/package.json +3 -3
- package/params.d.ts +1 -1
package/InjectPinoLogger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from '@nestjs/common';
|
|
2
2
|
import { PinoLogger } from './PinoLogger';
|
|
3
|
-
export declare function InjectPinoLogger(context?: string): (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
3
|
+
export declare function InjectPinoLogger(context?: string): (target: object, key: string | symbol | undefined, index?: number | undefined) => void;
|
|
4
4
|
export declare function createProvidersForDecorated(): Array<Provider<PinoLogger>>;
|
|
5
5
|
export declare function getLoggerToken(context: string): string;
|
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/README.md
CHANGED
|
@@ -175,7 +175,7 @@ The following interface is using for the configuration:
|
|
|
175
175
|
interface Params {
|
|
176
176
|
/**
|
|
177
177
|
* Optional parameters for `pino-http` module
|
|
178
|
-
* @see https://github.com/pinojs/pino-http#
|
|
178
|
+
* @see https://github.com/pinojs/pino-http#api
|
|
179
179
|
*/
|
|
180
180
|
pinoHttp?:
|
|
181
181
|
| pinoHttp.Options
|
|
@@ -242,8 +242,13 @@ import { LoggerModule } from 'nestjs-pino';
|
|
|
242
242
|
transport: process.env.NODE_ENV !== 'production'
|
|
243
243
|
? { target: 'pino-pretty' }
|
|
244
244
|
: undefined,
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
// and all the other fields of:
|
|
248
|
+
// - https://github.com/pinojs/pino-http#api
|
|
249
|
+
// - https://github.com/pinojs/pino/blob/HEAD/docs/api.md#options-object
|
|
250
|
+
|
|
251
|
+
|
|
247
252
|
},
|
|
248
253
|
someWritableStream
|
|
249
254
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-pino",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2-alpha.04bd16",
|
|
4
4
|
"description": "Pino logger for NestJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -58,10 +58,10 @@
|
|
|
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
|
-
"rimraf": "^
|
|
64
|
+
"rimraf": "^4.0.4",
|
|
65
65
|
"rxjs": "^7.2.0",
|
|
66
66
|
"supertest": "^6.1.3",
|
|
67
67
|
"ts-jest": "^27.0.3",
|
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 {
|