@edirect/logger 11.0.57 → 11.0.59
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/dist/package.json +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/logger/interfaces/logger-module-options.interface.d.ts +5 -10
- package/dist/src/logger/interfaces/logger-module-options.interface.d.ts.map +1 -1
- package/dist/src/logger/log.d.ts.map +1 -1
- package/dist/src/logger/log.js +24 -75
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/logger",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.59",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@edirect/config": "^11.0.
|
|
19
|
+
"@edirect/config": "^11.0.59",
|
|
20
20
|
"@nestjs/common": "^11.1.19",
|
|
21
21
|
"pino": "10.3.1",
|
|
22
22
|
"supertest": "7.2.2",
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qDAAqD,CAAC;AACpE,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./context/async-context"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./logger/interfaces/logger-module-options.interface"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./logger/logger.class"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./logger/logger.module"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./logger/logger.service"), exports);
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import { Level } from 'pino';
|
|
1
|
+
import { Level, LoggerOptions } from 'pino';
|
|
2
2
|
export interface LoggerModuleOptions {
|
|
3
|
-
output?: 'console'
|
|
4
|
-
logs?: {
|
|
5
|
-
errorFile: string;
|
|
6
|
-
warningFile: string;
|
|
7
|
-
infoFile: string;
|
|
8
|
-
exceptionsFile?: string;
|
|
9
|
-
minLength?: number;
|
|
10
|
-
sync?: boolean;
|
|
11
|
-
};
|
|
3
|
+
output?: 'console';
|
|
12
4
|
name?: string;
|
|
13
5
|
host?: string;
|
|
14
6
|
protocol?: string;
|
|
15
7
|
version?: string;
|
|
16
8
|
level?: Level;
|
|
17
9
|
payloadFieldName?: 'details' | 'payload';
|
|
10
|
+
mixin?: () => Record<string, unknown>;
|
|
11
|
+
baseExtension?: Record<string, unknown>;
|
|
12
|
+
pinoOptions?: Omit<LoggerOptions, 'level' | 'timestamp' | 'messageKey' | 'errorKey' | 'formatters' | 'base' | 'mixin'>;
|
|
18
13
|
}
|
|
19
14
|
//# sourceMappingURL=logger-module-options.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-module-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/logger/interfaces/logger-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"logger-module-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/logger/interfaces/logger-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,gBAAgB,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,IAAI,CAChB,aAAa,EACb,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,CACpF,CAAC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/logger/log.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/logger/log.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAEnF,MAAM,WAAW,WAAW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E,MAAM,EACd,aAAa,CAAC,EAAE,MAAM,GACrB,IAAI;IA+CP,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAIrE,UAAU,CAAC,GAAG,EAAE,MAAM,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzD,OAAO,CAAC,QAAQ;CAmCjB"}
|
package/dist/src/logger/log.js
CHANGED
|
@@ -2,71 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const pino_1 = tslib_1.
|
|
5
|
+
const pino_1 = tslib_1.__importDefault(require("pino"));
|
|
6
6
|
const async_context_1 = require("../context/async-context");
|
|
7
7
|
class Logger {
|
|
8
8
|
configs;
|
|
9
9
|
logger;
|
|
10
10
|
constructor(env, options) {
|
|
11
11
|
const defaults = {
|
|
12
|
-
logs: {
|
|
13
|
-
infoFile: env.LOGS_INFO_FILE,
|
|
14
|
-
warningFile: env.LOGS_WARNING_FILE,
|
|
15
|
-
errorFile: env.LOGS_ERROR_FILE,
|
|
16
|
-
exceptionsFile: env.LOGS_EXCEPTIONS_FILE,
|
|
17
|
-
},
|
|
18
12
|
level: env.LOGS_LEVEL?.toLowerCase() || 'info',
|
|
19
|
-
output: env.LOGS_OUTPUT ?? 'console',
|
|
20
13
|
name: env.npm_package_name ?? env.APP_NAME ?? 'app',
|
|
21
14
|
version: env.npm_package_version ?? env.APP_VERSION ?? '0.0.0',
|
|
22
15
|
host: env.LOGS_HOST ?? '0.0.0.0',
|
|
23
16
|
protocol: env.LOGS_PROTOCOL ?? 'http',
|
|
24
|
-
payloadFieldName: env.LOGS_PAYLOAD_FIELD_NAME ??
|
|
17
|
+
payloadFieldName: env.LOGS_PAYLOAD_FIELD_NAME ??
|
|
18
|
+
'payload',
|
|
25
19
|
};
|
|
26
20
|
this.configs = { ...defaults, ...options };
|
|
27
|
-
const streams = [];
|
|
28
|
-
if (this.configs.output === 'file' || this.configs.output === 'both') {
|
|
29
|
-
if (this.configs.logs?.infoFile) {
|
|
30
|
-
streams.push({
|
|
31
|
-
level: 'info',
|
|
32
|
-
stream: pino_1.default.destination({
|
|
33
|
-
dest: this.configs.logs.infoFile,
|
|
34
|
-
mkdir: true,
|
|
35
|
-
sync: this.configs.logs.sync ?? false,
|
|
36
|
-
minLength: this.configs.logs.minLength ?? 4096,
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (this.configs.logs?.warningFile) {
|
|
41
|
-
streams.push({
|
|
42
|
-
level: 'warn',
|
|
43
|
-
stream: pino_1.default.destination({
|
|
44
|
-
dest: this.configs.logs.warningFile,
|
|
45
|
-
mkdir: true,
|
|
46
|
-
sync: this.configs.logs.sync ?? false,
|
|
47
|
-
minLength: this.configs.logs.minLength ?? 4096,
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (this.configs.logs?.errorFile) {
|
|
52
|
-
streams.push({
|
|
53
|
-
level: 'error',
|
|
54
|
-
stream: pino_1.default.destination({
|
|
55
|
-
dest: this.configs.logs.errorFile,
|
|
56
|
-
mkdir: true,
|
|
57
|
-
sync: this.configs.logs.sync ?? false,
|
|
58
|
-
minLength: this.configs.logs.minLength ?? 4096,
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (this.configs.output === 'console' || this.configs.output === 'both') {
|
|
64
|
-
streams.push({
|
|
65
|
-
level: this.configs.level,
|
|
66
|
-
stream: process.stdout,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
21
|
this.logger = (0, pino_1.default)({
|
|
22
|
+
...(this.configs.pinoOptions ?? {}),
|
|
70
23
|
level: this.configs.level,
|
|
71
24
|
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
72
25
|
messageKey: 'message',
|
|
@@ -76,31 +29,13 @@ class Logger {
|
|
|
76
29
|
version: this.configs.version,
|
|
77
30
|
host: this.configs.host,
|
|
78
31
|
protocol: this.configs.protocol,
|
|
32
|
+
...this.configs.baseExtension,
|
|
79
33
|
},
|
|
80
34
|
formatters: {
|
|
81
35
|
level: label => ({ level: label }),
|
|
82
36
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const exceptionLogger = (0, pino_1.default)({
|
|
86
|
-
level: 'fatal',
|
|
87
|
-
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
88
|
-
messageKey: 'message',
|
|
89
|
-
errorKey: 'error',
|
|
90
|
-
}, pino_1.default.destination({
|
|
91
|
-
dest: this.configs.logs.exceptionsFile,
|
|
92
|
-
mkdir: true,
|
|
93
|
-
sync: true,
|
|
94
|
-
}));
|
|
95
|
-
process.on('uncaughtException', err => {
|
|
96
|
-
exceptionLogger.fatal({ err }, 'Uncaught exception');
|
|
97
|
-
process.exit(1);
|
|
98
|
-
});
|
|
99
|
-
process.on('unhandledRejection', reason => {
|
|
100
|
-
exceptionLogger.fatal({ reason }, 'Unhandled rejection');
|
|
101
|
-
process.exit(1);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
37
|
+
...(this.configs.mixin ? { mixin: this.configs.mixin } : {}),
|
|
38
|
+
});
|
|
104
39
|
}
|
|
105
40
|
debug(message, payload, remoteAddress) {
|
|
106
41
|
this.logger.debug(this.buildLog(payload, remoteAddress), message);
|
|
@@ -131,12 +66,15 @@ class Logger {
|
|
|
131
66
|
finalTrace = traceOrErrorOrPayload;
|
|
132
67
|
finalRemoteAddress = traceOrRemoteAddress || '';
|
|
133
68
|
}
|
|
134
|
-
else if (traceOrErrorOrPayload !== undefined &&
|
|
69
|
+
else if (traceOrErrorOrPayload !== undefined &&
|
|
70
|
+
typeof traceOrRemoteAddress === 'string' &&
|
|
71
|
+
remoteAddress !== undefined) {
|
|
135
72
|
finalPayload = finalPayload || traceOrErrorOrPayload;
|
|
136
73
|
finalTrace = traceOrRemoteAddress;
|
|
137
74
|
finalRemoteAddress = remoteAddress;
|
|
138
75
|
}
|
|
139
|
-
else if (traceOrErrorOrPayload !== undefined &&
|
|
76
|
+
else if (traceOrErrorOrPayload !== undefined &&
|
|
77
|
+
typeof traceOrRemoteAddress === 'string') {
|
|
140
78
|
finalPayload = finalPayload || traceOrErrorOrPayload;
|
|
141
79
|
finalTrace = traceOrRemoteAddress;
|
|
142
80
|
}
|
|
@@ -168,7 +106,18 @@ class Logger {
|
|
|
168
106
|
metadata['remote-address'] = remoteAddress;
|
|
169
107
|
if (payload !== undefined) {
|
|
170
108
|
const fieldName = this.configs.payloadFieldName ?? 'payload';
|
|
171
|
-
|
|
109
|
+
if (typeof payload === 'string' &&
|
|
110
|
+
(payload.startsWith('{') || payload.startsWith('['))) {
|
|
111
|
+
try {
|
|
112
|
+
metadata[fieldName] = JSON.parse(payload);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
metadata[fieldName] = payload;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
metadata[fieldName] = payload;
|
|
120
|
+
}
|
|
172
121
|
}
|
|
173
122
|
if (trace)
|
|
174
123
|
metadata.trace = trace;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/logger",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.59",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"pino": "10.3.1",
|
|
22
22
|
"supertest": "7.2.2",
|
|
23
23
|
"tslib": "^2.8.1",
|
|
24
|
-
"@edirect/config": "11.0.
|
|
24
|
+
"@edirect/config": "11.0.59"
|
|
25
25
|
},
|
|
26
26
|
"nx": {
|
|
27
27
|
"name": "@edirect/logger",
|