@rxap/nest-logger 10.2.11-dev.0 → 10.3.0-dev.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/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/src/lib/logger.d.ts +8 -10
- package/src/lib/logger.js +53 -61
- package/src/lib/tokens.d.ts +1 -0
- package/src/lib/tokens.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.3.0-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-logger@10.2.11-dev.0...@rxap/nest-logger@10.3.0-dev.0) (2025-01-16)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- support custom print messages function ([db34f07](https://gitlab.com/rxap/packages/commit/db34f070178b9ea7a453304e7f66d20d3a508e01))
|
|
11
|
+
|
|
6
12
|
## [10.2.11-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-logger@10.2.10...@rxap/nest-logger@10.2.11-dev.0) (2025-01-08)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @rxap/nest-logger
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.
|
|
2
|
+
"version": "10.3.0-dev.0",
|
|
3
3
|
"name": "@rxap/nest-logger",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"dependencies": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"directory": "packages/nest/logger"
|
|
51
51
|
},
|
|
52
52
|
"type": "commonjs",
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "897ab34bff42ac956e06340c5e3cfe7b1deff11c",
|
|
54
54
|
"types": "./src/index.d.ts",
|
|
55
55
|
"main": "./src/index.js"
|
|
56
56
|
}
|
package/src/lib/logger.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { ConsoleLogger, ConsoleLoggerOptions, LogLevel } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* @return true - call the super.printMessages method
|
|
4
|
+
*/
|
|
5
|
+
export type PrintMessagesFunction = (messages: unknown[], context: string, logLevel: LogLevel, writeStreamType?: 'stdout' | 'stderr') => boolean;
|
|
2
6
|
/**
|
|
3
7
|
* A custom logger class that extends the ConsoleLogger class.
|
|
4
8
|
* This class provides additional methods for logging at different log levels and supports the interpolation of optional parameters.
|
|
5
9
|
*/
|
|
6
10
|
export declare class RxapLogger extends ConsoleLogger {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
warn(message: string, ...optionalParams: any[]): void;
|
|
11
|
-
debug(message: string, ...optionalParams: any[]): void;
|
|
12
|
-
verbose(message: string, ...optionalParams: any[]): void;
|
|
13
|
-
protected interpolate(message: unknown, optionalParams: any[], logLevel: LogLevel): {
|
|
14
|
-
msg: unknown;
|
|
15
|
-
params: any[];
|
|
16
|
-
};
|
|
11
|
+
protected readonly printMessagesFunction: PrintMessagesFunction | null;
|
|
12
|
+
constructor(context?: string, options?: ConsoleLoggerOptions, printMessagesFunction?: PrintMessagesFunction | null);
|
|
13
|
+
protected interpolate(messages: unknown[]): unknown[];
|
|
17
14
|
protected stringifyCircular(obj: any): string;
|
|
15
|
+
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, writeStreamType?: 'stdout' | 'stderr'): void;
|
|
18
16
|
}
|
package/src/lib/logger.js
CHANGED
|
@@ -9,70 +9,49 @@ const tokens_1 = require("./tokens");
|
|
|
9
9
|
* This class provides additional methods for logging at different log levels and supports the interpolation of optional parameters.
|
|
10
10
|
*/
|
|
11
11
|
let RxapLogger = class RxapLogger extends common_1.ConsoleLogger {
|
|
12
|
-
constructor(context, options = {}) {
|
|
12
|
+
constructor(context, options = {}, printMessagesFunction = null) {
|
|
13
13
|
super(context, options);
|
|
14
|
+
this.printMessagesFunction = printMessagesFunction;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const { msg, params, } = this.interpolate(message, optionalParams, 'verbose');
|
|
33
|
-
super.verbose(msg, ...params);
|
|
34
|
-
}
|
|
35
|
-
interpolate(message, optionalParams, logLevel) {
|
|
36
|
-
if (this.isLevelEnabled(logLevel) && typeof message === 'string') {
|
|
37
|
-
if (message.includes('%JSON')) {
|
|
38
|
-
// replace each %JSON with the corresponding optionalParam
|
|
39
|
-
const msg = message.replace(/%JSON/g, () => {
|
|
40
|
-
if (optionalParams.length) {
|
|
41
|
-
const param = optionalParams.shift();
|
|
42
|
-
if (typeof param === 'object') {
|
|
43
|
-
if (param) {
|
|
44
|
-
return this.stringifyCircular(param);
|
|
45
|
-
}
|
|
46
|
-
else if (param === null) {
|
|
47
|
-
return '<null>';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (typeof param === 'undefined') {
|
|
51
|
-
return '<undefined>';
|
|
52
|
-
}
|
|
53
|
-
if (typeof param === 'string') {
|
|
54
|
-
return JSON.stringify(param);
|
|
55
|
-
}
|
|
56
|
-
if (typeof param === 'number') {
|
|
57
|
-
return JSON.stringify(param);
|
|
58
|
-
}
|
|
59
|
-
if (typeof param === 'boolean') {
|
|
60
|
-
return JSON.stringify(param);
|
|
61
|
-
}
|
|
62
|
-
optionalParams.unshift(param);
|
|
16
|
+
interpolate(messages) {
|
|
17
|
+
if (messages.length <= 1) {
|
|
18
|
+
return messages;
|
|
19
|
+
}
|
|
20
|
+
if (typeof messages[0] !== 'string') {
|
|
21
|
+
return messages;
|
|
22
|
+
}
|
|
23
|
+
if (!messages[0].includes('%JSON')) {
|
|
24
|
+
return messages;
|
|
25
|
+
}
|
|
26
|
+
let message = messages.shift();
|
|
27
|
+
message = message.replace(/%JSON/g, () => {
|
|
28
|
+
if (messages.length) {
|
|
29
|
+
const param = messages.shift();
|
|
30
|
+
if (typeof param === 'object') {
|
|
31
|
+
if (param) {
|
|
32
|
+
return this.stringifyCircular(param);
|
|
63
33
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
34
|
+
else if (param === null) {
|
|
35
|
+
return '<null>';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (typeof param === 'undefined') {
|
|
39
|
+
return '<undefined>';
|
|
40
|
+
}
|
|
41
|
+
if (typeof param === 'string') {
|
|
42
|
+
return JSON.stringify(param);
|
|
43
|
+
}
|
|
44
|
+
if (typeof param === 'number') {
|
|
45
|
+
return JSON.stringify(param);
|
|
46
|
+
}
|
|
47
|
+
if (typeof param === 'boolean') {
|
|
48
|
+
return JSON.stringify(param);
|
|
49
|
+
}
|
|
50
|
+
messages.unshift(param);
|
|
70
51
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
params: optionalParams,
|
|
75
|
-
};
|
|
52
|
+
return '<json>';
|
|
53
|
+
});
|
|
54
|
+
return [message, ...messages];
|
|
76
55
|
}
|
|
77
56
|
stringifyCircular(obj) {
|
|
78
57
|
const seenObjects = new Set();
|
|
@@ -87,6 +66,17 @@ let RxapLogger = class RxapLogger extends common_1.ConsoleLogger {
|
|
|
87
66
|
return value;
|
|
88
67
|
});
|
|
89
68
|
}
|
|
69
|
+
printMessages(messages, context = '', logLevel = 'log', writeStreamType) {
|
|
70
|
+
if (this.printMessagesFunction) {
|
|
71
|
+
const call = this.printMessagesFunction(messages, context, logLevel, writeStreamType);
|
|
72
|
+
if (call) {
|
|
73
|
+
super.printMessages(this.interpolate(messages), context, logLevel, writeStreamType);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
super.printMessages(this.interpolate(messages), context, logLevel, writeStreamType);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
90
80
|
};
|
|
91
81
|
exports.RxapLogger = RxapLogger;
|
|
92
82
|
exports.RxapLogger = RxapLogger = tslib_1.__decorate([
|
|
@@ -94,5 +84,7 @@ exports.RxapLogger = RxapLogger = tslib_1.__decorate([
|
|
|
94
84
|
tslib_1.__param(0, (0, common_1.Optional)()),
|
|
95
85
|
tslib_1.__param(1, (0, common_1.Inject)(tokens_1.CONSOLE_LOGGER_OPTIONS)),
|
|
96
86
|
tslib_1.__param(1, (0, common_1.Optional)()),
|
|
97
|
-
tslib_1.
|
|
87
|
+
tslib_1.__param(2, (0, common_1.Optional)()),
|
|
88
|
+
tslib_1.__param(2, (0, common_1.Inject)(tokens_1.RXAP_LOGGER_PRINT_MESSAGES)),
|
|
89
|
+
tslib_1.__metadata("design:paramtypes", [String, Object, Object])
|
|
98
90
|
], RxapLogger);
|
package/src/lib/tokens.d.ts
CHANGED
package/src/lib/tokens.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONSOLE_LOGGER_OPTIONS = void 0;
|
|
3
|
+
exports.RXAP_LOGGER_PRINT_MESSAGES = exports.CONSOLE_LOGGER_OPTIONS = void 0;
|
|
4
4
|
exports.CONSOLE_LOGGER_OPTIONS = Symbol('CONSOLE_LOGGER_OPTIONS');
|
|
5
|
+
exports.RXAP_LOGGER_PRINT_MESSAGES = Symbol('RXAP_LOGGER_PRINT_MESSAGES');
|