nestjs-pino 2.3.0-alpha.3500df → 2.3.0-alpha.467e2f
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/PinoLogger.d.ts +0 -4
- package/PinoLogger.js +8 -8
- package/README.md +4 -4
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/package.json +1 -1
- package/assign.d.ts +0 -6
- package/assign.js +0 -18
package/PinoLogger.d.ts
CHANGED
|
@@ -27,10 +27,6 @@ export declare class PinoLogger implements PinoMethods {
|
|
|
27
27
|
setContext(value: string): void;
|
|
28
28
|
private call;
|
|
29
29
|
get logger(): pino.Logger;
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated in favour of `assign` function from the package.
|
|
32
|
-
* No need to inject `PinoLogger`
|
|
33
|
-
*/
|
|
34
30
|
assign(fields: pino.Bindings): void;
|
|
35
31
|
}
|
|
36
32
|
export {};
|
package/PinoLogger.js
CHANGED
|
@@ -11,12 +11,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var PinoLogger_1;
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.PinoLogger = exports.__resetOutOfContextForTests = void 0;
|
|
16
17
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
17
18
|
const common_1 = require("@nestjs/common");
|
|
18
19
|
const pino = require("pino");
|
|
19
|
-
const assign_1 = require("./assign");
|
|
20
20
|
const params_1 = require("./params");
|
|
21
21
|
const storage_1 = require("./storage");
|
|
22
22
|
let outOfContext;
|
|
@@ -26,7 +26,7 @@ function __resetOutOfContextForTests() {
|
|
|
26
26
|
PinoLogger.root = undefined;
|
|
27
27
|
}
|
|
28
28
|
exports.__resetOutOfContextForTests = __resetOutOfContextForTests;
|
|
29
|
-
let PinoLogger = class PinoLogger {
|
|
29
|
+
let PinoLogger = PinoLogger_1 = class PinoLogger {
|
|
30
30
|
constructor({ pinoHttp, renameContext }) {
|
|
31
31
|
this.context = '';
|
|
32
32
|
if (!outOfContext) {
|
|
@@ -98,15 +98,15 @@ let PinoLogger = class PinoLogger {
|
|
|
98
98
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
99
|
return ((_a = storage_1.storage.getStore()) === null || _a === void 0 ? void 0 : _a.logger) || outOfContext;
|
|
100
100
|
}
|
|
101
|
-
/**
|
|
102
|
-
* @deprecated in favour of `assign` function from the package.
|
|
103
|
-
* No need to inject `PinoLogger`
|
|
104
|
-
*/
|
|
105
101
|
assign(fields) {
|
|
106
|
-
|
|
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
107
|
}
|
|
108
108
|
};
|
|
109
|
-
PinoLogger = __decorate([
|
|
109
|
+
PinoLogger = PinoLogger_1 = __decorate([
|
|
110
110
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
111
111
|
__param(0, (0, common_1.Inject)(params_1.PARAMS_PROVIDER_TOKEN)),
|
|
112
112
|
__metadata("design:paramtypes", [Object])
|
package/README.md
CHANGED
|
@@ -378,21 +378,21 @@ With such change it's not possible to detect if method was called by app interna
|
|
|
378
378
|
|
|
379
379
|
## Assign extra fields for future calls
|
|
380
380
|
|
|
381
|
-
You can enrich logs before calling log methods. It's possible by using `assign`
|
|
381
|
+
You can enrich logs before calling log methods. It's possible by using `assign` method of `PinoLogger` instance. As `Logger` class is used only for NestJS built-in `Logger` substitution via `app.useLogger(...)` this feature is only limited to `PinoLogger` class. Example:
|
|
382
382
|
|
|
383
383
|
```ts
|
|
384
|
-
import { assign } from 'nestjs-pino';
|
|
385
384
|
|
|
386
385
|
@Controller('/')
|
|
387
386
|
class TestController {
|
|
388
387
|
constructor(
|
|
388
|
+
private readonly logger: PinoLogger,
|
|
389
389
|
private readonly service: MyService,
|
|
390
390
|
) {}
|
|
391
391
|
|
|
392
392
|
@Get()
|
|
393
393
|
get() {
|
|
394
394
|
// assign extra fields in one place...
|
|
395
|
-
assign({ userID: '42' });
|
|
395
|
+
this.logger.assign({ userID: '42' });
|
|
396
396
|
return this.service.test();
|
|
397
397
|
}
|
|
398
398
|
}
|
|
@@ -408,7 +408,7 @@ class MyService {
|
|
|
408
408
|
}
|
|
409
409
|
```
|
|
410
410
|
|
|
411
|
-
Due to the [limitation](https://github.com/pinojs/pino-http/issues/30) of the underlying `http
|
|
411
|
+
Due to the [limitation](https://github.com/pinojs/pino-http/issues/30) of the underlying `pino-http` `PinoLogger.assign` cannot extend `Request completed` logs.
|
|
412
412
|
|
|
413
413
|
## Change pino params at runtime
|
|
414
414
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PARAMS_PROVIDER_TOKEN = exports.getLoggerToken = exports.InjectPinoLogger = exports.PinoLogger = exports.Logger = exports.LoggerModule = void 0;
|
|
4
4
|
var LoggerModule_1 = require("./LoggerModule");
|
|
5
5
|
Object.defineProperty(exports, "LoggerModule", { enumerable: true, get: function () { return LoggerModule_1.LoggerModule; } });
|
|
6
6
|
var Logger_1 = require("./Logger");
|
|
@@ -12,6 +12,4 @@ Object.defineProperty(exports, "InjectPinoLogger", { enumerable: true, get: func
|
|
|
12
12
|
Object.defineProperty(exports, "getLoggerToken", { enumerable: true, get: function () { return InjectPinoLogger_1.getLoggerToken; } });
|
|
13
13
|
var params_1 = require("./params");
|
|
14
14
|
Object.defineProperty(exports, "PARAMS_PROVIDER_TOKEN", { enumerable: true, get: function () { return params_1.PARAMS_PROVIDER_TOKEN; } });
|
|
15
|
-
var assign_1 = require("./assign");
|
|
16
|
-
Object.defineProperty(exports, "assign", { enumerable: true, get: function () { return assign_1.assign; } });
|
|
17
15
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/assign.d.ts
DELETED
package/assign.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assign = void 0;
|
|
4
|
-
const storage_1 = require("./storage");
|
|
5
|
-
const PinoLogger_1 = require("./PinoLogger");
|
|
6
|
-
/**
|
|
7
|
-
* assign replaces current logger with the child one containing passed fields
|
|
8
|
-
* @param fields
|
|
9
|
-
*/
|
|
10
|
-
function assign(fields) {
|
|
11
|
-
const store = storage_1.storage.getStore();
|
|
12
|
-
if (!store) {
|
|
13
|
-
throw new Error(`${PinoLogger_1.PinoLogger.name}: unable to assign extra fields out of request scope`);
|
|
14
|
-
}
|
|
15
|
-
store.logger = store.logger.child(fields);
|
|
16
|
-
}
|
|
17
|
-
exports.assign = assign;
|
|
18
|
-
//# sourceMappingURL=assign.js.map
|