@xrystal/core 3.17.4 → 3.17.6
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/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
2
|
import "winston-daily-rotate-file";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
import ConfigsService from "../configs";
|
|
5
4
|
import { LoggerLayerEnum, IService } from "../../utils";
|
|
6
5
|
interface CustomLogger extends winston.Logger {
|
|
7
6
|
critical: winston.LeveledLogMethod;
|
|
@@ -20,15 +19,13 @@ export default class LoggerService implements IService {
|
|
|
20
19
|
private kafkaProducer;
|
|
21
20
|
private kafkaTopic;
|
|
22
21
|
private isKafkaReady;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
22
|
+
winston: CustomLogger;
|
|
23
|
+
constructor(deps: any);
|
|
26
24
|
load: (config: Record<string, any>) => Promise<void>;
|
|
27
25
|
winstonLoader: ({ loadPath, loggerLevel }: {
|
|
28
26
|
loadPath: string;
|
|
29
27
|
loggerLevel: string;
|
|
30
28
|
}) => CustomLogger;
|
|
31
|
-
winston: CustomLogger;
|
|
32
29
|
private safeReplacer;
|
|
33
30
|
private getTracingFormat;
|
|
34
31
|
private getConsoleFormat;
|
|
@@ -37,10 +37,20 @@ export default class LoggerService {
|
|
|
37
37
|
kafkaProducer = null;
|
|
38
38
|
kafkaTopic = "";
|
|
39
39
|
isKafkaReady = false;
|
|
40
|
+
winston;
|
|
40
41
|
#configsService;
|
|
41
|
-
constructor(
|
|
42
|
-
|
|
42
|
+
constructor(deps) {
|
|
43
|
+
if (!deps || !deps.configsService) {
|
|
44
|
+
throw new Error("LoggerService: configsService is required");
|
|
45
|
+
}
|
|
46
|
+
this.#configsService = deps.configsService;
|
|
43
47
|
winston.addColors(customColors);
|
|
48
|
+
this.winston = winston.createLogger({
|
|
49
|
+
level: this.#configsService.all.systemLoggerLayer || 'info',
|
|
50
|
+
levels: customLevels,
|
|
51
|
+
format: this.getConsoleFormat(),
|
|
52
|
+
transports: [new winston.transports.Console()]
|
|
53
|
+
});
|
|
44
54
|
}
|
|
45
55
|
load = async (config) => {
|
|
46
56
|
this.serviceName = config?.serviceName || "service";
|
|
@@ -108,12 +118,6 @@ export default class LoggerService {
|
|
|
108
118
|
});
|
|
109
119
|
return this.winston;
|
|
110
120
|
};
|
|
111
|
-
winston = winston.createLogger({
|
|
112
|
-
level: this.#configsService.all.systemLoggerLayer,
|
|
113
|
-
levels: customLevels,
|
|
114
|
-
format: this.getConsoleFormat(),
|
|
115
|
-
transports: [new winston.transports.Console()]
|
|
116
|
-
});
|
|
117
121
|
safeReplacer = (key, value) => {
|
|
118
122
|
if (value instanceof Headers)
|
|
119
123
|
return Object.fromEntries(value.entries());
|
|
@@ -167,7 +171,8 @@ export default class LoggerService {
|
|
|
167
171
|
id: id || null,
|
|
168
172
|
env: this.#configsService.all.env
|
|
169
173
|
}, this.safeReplacer)
|
|
170
|
-
}]
|
|
174
|
+
}],
|
|
175
|
+
acks: 0
|
|
171
176
|
});
|
|
172
177
|
}
|
|
173
178
|
catch (err) {
|
|
@@ -175,23 +180,10 @@ export default class LoggerService {
|
|
|
175
180
|
}
|
|
176
181
|
}
|
|
177
182
|
log(arg1, arg2, arg3, arg4) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
level = arg1.level;
|
|
184
|
-
message = arg1.message;
|
|
185
|
-
payload = arg1.payload;
|
|
186
|
-
code = arg1.code;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
level = arg1;
|
|
190
|
-
message = arg2;
|
|
191
|
-
payload = arg3;
|
|
192
|
-
code = arg4;
|
|
193
|
-
}
|
|
194
|
-
const levelName = LoggerLayerEnum[level].toLowerCase();
|
|
195
|
-
this.winston.log(levelName, message, { payload, code });
|
|
183
|
+
const isObj = typeof arg1 === 'object' && arg1 !== null && 'level' in arg1;
|
|
184
|
+
const { level, message, payload, code } = isObj
|
|
185
|
+
? arg1
|
|
186
|
+
: { level: arg1, message: arg2, payload: arg3, code: arg4 };
|
|
187
|
+
this.winston.log(LoggerLayerEnum[level].toLowerCase(), message, { payload, code });
|
|
196
188
|
}
|
|
197
189
|
}
|