@infineit/winston-logger 1.0.30 → 1.0.32
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/README.md +2206 -114
- package/context/infrastructure/nestjs/contextModule.js +2 -4
- package/context/infrastructure/nestjs/contextModule.js.map +1 -1
- package/index.d.ts +19 -5
- package/index.js +29 -5
- package/index.js.map +1 -1
- package/logger/domain/log.d.ts +3 -1
- package/logger/domain/loggerService.d.ts +9 -4
- package/logger/domain/loggerService.js +153 -31
- package/logger/domain/loggerService.js.map +1 -1
- package/logger/domain/loggerTransport.d.ts +5 -0
- package/logger/domain/loggerTransport.js +5 -0
- package/logger/domain/loggerTransport.js.map +1 -0
- package/logger/domain/normalizedLog.d.ts +23 -0
- package/logger/domain/normalizedLog.js +37 -0
- package/logger/domain/normalizedLog.js.map +1 -0
- package/logger/infrastructure/forwarding/centralLogForwarder.d.ts +15 -0
- package/logger/infrastructure/forwarding/centralLogForwarder.js +81 -0
- package/logger/infrastructure/forwarding/centralLogForwarder.js.map +1 -0
- package/logger/infrastructure/forwarding/httpCentralLogForwarder.d.ts +8 -0
- package/logger/infrastructure/forwarding/httpCentralLogForwarder.js +88 -0
- package/logger/infrastructure/forwarding/httpCentralLogForwarder.js.map +1 -0
- package/logger/infrastructure/forwarding/kafkaCentralLogForwarder.d.ts +9 -0
- package/logger/infrastructure/forwarding/kafkaCentralLogForwarder.js +50 -0
- package/logger/infrastructure/forwarding/kafkaCentralLogForwarder.js.map +1 -0
- package/logger/infrastructure/nestjs/loggerModule.d.ts +16 -9
- package/logger/infrastructure/nestjs/loggerModule.js +86 -136
- package/logger/infrastructure/nestjs/loggerModule.js.map +1 -1
- package/logger/infrastructure/nestjs/nestjsLoggerServiceAdapter.js +61 -11
- package/logger/infrastructure/nestjs/nestjsLoggerServiceAdapter.js.map +1 -1
- package/logger/infrastructure/winston/transports/fileTransport.d.ts +1 -1
- package/logger/infrastructure/winston/transports/fileTransport.js +5 -2
- package/logger/infrastructure/winston/transports/fileTransport.js.map +1 -1
- package/logger/infrastructure/winston/winstonLogger.js +78 -27
- package/logger/infrastructure/winston/winstonLogger.js.map +1 -1
- package/logger/infrastructure/winston/winstonTransportAdapter.d.ts +10 -0
- package/logger/infrastructure/winston/winstonTransportAdapter.js +128 -0
- package/logger/infrastructure/winston/winstonTransportAdapter.js.map +1 -0
- package/package.json +10 -14
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/logger/infrastructure/winston/transports/prisma-transport.d.ts +0 -11
- package/logger/infrastructure/winston/transports/prisma-transport.js +0 -50
- package/logger/infrastructure/winston/transports/prisma-transport.js.map +0 -1
- package/logger/levelFilter.d.ts +0 -2
- package/logger/levelFilter.js +0 -47
- package/logger/levelFilter.js.map +0 -1
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ContextModule = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
-
const uuid_1 = require("uuid");
|
|
16
15
|
const contextStorageService_1 = require("../../../context/domain/interfaces/contextStorageService");
|
|
17
16
|
const nestjsClsContextStorageService_1 = __importDefault(require("../../../context/infrastructure/nestjs-cls/nestjsClsContextStorageService"));
|
|
18
17
|
let ContextModule = class ContextModule {
|
|
@@ -25,9 +24,8 @@ exports.ContextModule = ContextModule = __decorate([
|
|
|
25
24
|
nestjs_cls_1.ClsModule.forRoot({
|
|
26
25
|
global: true,
|
|
27
26
|
middleware: {
|
|
28
|
-
mount:
|
|
29
|
-
generateId:
|
|
30
|
-
idGenerator: (req) => req.headers['x-correlation-id'] ?? (0, uuid_1.v4)(),
|
|
27
|
+
mount: false,
|
|
28
|
+
generateId: false,
|
|
31
29
|
},
|
|
32
30
|
}),
|
|
33
31
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextModule.js","sourceRoot":"","sources":["../../../../../libs/src/context/infrastructure/nestjs/contextModule.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAgD;AAEhD,2CAAuC;
|
|
1
|
+
{"version":3,"file":"contextModule.js","sourceRoot":"","sources":["../../../../../libs/src/context/infrastructure/nestjs/contextModule.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAgD;AAEhD,2CAAuC;AAEvC,oGAAoG;AACpG,+IAAuH;AAsChH,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAtBzB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE;YAGL,sBAAS,CAAC,OAAO,CAAC;gBACd,MAAM,EAAE,IAAI;gBACZ,UAAU,EAAE;oBACR,KAAK,EAAE,KAAK;oBACZ,UAAU,EAAE,KAAK;iBACpB;aACJ,CAAC;SACL;QACD,WAAW,EAAE,EAAE;QACf,SAAS,EAAE;YACP;gBACI,OAAO,EAAE,gDAAwB;gBACjC,QAAQ,EAAE,wCAA8B;aAC3C;SACJ;QACD,OAAO,EAAE,CAAC,gDAAwB,CAAC;KACtC,CAAC;GACW,aAAa,CAAG"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { ContextModule } from './context/infrastructure/nestjs/contextModule';
|
|
2
|
+
export { LoggerModule, LoggerModuleConfig } from './logger/infrastructure/nestjs/loggerModule';
|
|
3
|
+
export { default as NestjsLoggerServiceAdapter } from './logger/infrastructure/nestjs/nestjsLoggerServiceAdapter';
|
|
4
|
+
export { LoggerKey } from './logger/domain/logger';
|
|
5
|
+
export type { default as Logger } from './logger/domain/logger';
|
|
6
|
+
export { default as LoggerService } from './logger/domain/loggerService';
|
|
7
|
+
export { ContextStorageServiceKey } from './context/domain/interfaces/contextStorageService';
|
|
8
|
+
export type { default as ContextStorageService } from './context/domain/interfaces/contextStorageService';
|
|
9
|
+
export { LoggerTransport, LoggerTransportKey } from './logger/domain/loggerTransport';
|
|
10
|
+
export type { NormalizedLog, SerializedError } from './logger/domain/normalizedLog';
|
|
11
|
+
export { serializeError } from './logger/domain/normalizedLog';
|
|
12
|
+
export { LogLevel } from './logger/domain/log';
|
|
13
|
+
export type { LogData, Log } from './logger/domain/log';
|
|
14
|
+
export { WinstonTransportAdapter, WinstonTransportAdapterTransportsKey, } from './logger/infrastructure/winston/winstonTransportAdapter';
|
|
15
|
+
export { CentralLogForwarderKey, KafkaProducerKey, } from './logger/infrastructure/forwarding/centralLogForwarder';
|
|
16
|
+
export type { ICentralLogForwarder } from './logger/infrastructure/forwarding/centralLogForwarder';
|
|
17
|
+
export { CentralLogForwarder } from './logger/infrastructure/forwarding/centralLogForwarder';
|
|
18
|
+
export { KafkaCentralLogForwarder } from './logger/infrastructure/forwarding/kafkaCentralLogForwarder';
|
|
19
|
+
export { HttpCentralLogForwarder } from './logger/infrastructure/forwarding/httpCentralLogForwarder';
|
package/index.js
CHANGED
|
@@ -3,11 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.HttpCentralLogForwarder = exports.KafkaCentralLogForwarder = exports.CentralLogForwarder = exports.KafkaProducerKey = exports.CentralLogForwarderKey = exports.WinstonTransportAdapterTransportsKey = exports.WinstonTransportAdapter = exports.LogLevel = exports.serializeError = exports.LoggerTransportKey = exports.ContextStorageServiceKey = exports.LoggerService = exports.LoggerKey = exports.NestjsLoggerServiceAdapter = exports.LoggerModule = exports.ContextModule = void 0;
|
|
7
|
+
var contextModule_1 = require("./context/infrastructure/nestjs/contextModule");
|
|
8
8
|
Object.defineProperty(exports, "ContextModule", { enumerable: true, get: function () { return contextModule_1.ContextModule; } });
|
|
9
|
-
|
|
9
|
+
var loggerModule_1 = require("./logger/infrastructure/nestjs/loggerModule");
|
|
10
10
|
Object.defineProperty(exports, "LoggerModule", { enumerable: true, get: function () { return loggerModule_1.LoggerModule; } });
|
|
11
|
-
|
|
12
|
-
exports
|
|
11
|
+
var nestjsLoggerServiceAdapter_1 = require("./logger/infrastructure/nestjs/nestjsLoggerServiceAdapter");
|
|
12
|
+
Object.defineProperty(exports, "NestjsLoggerServiceAdapter", { enumerable: true, get: function () { return __importDefault(nestjsLoggerServiceAdapter_1).default; } });
|
|
13
|
+
var logger_1 = require("./logger/domain/logger");
|
|
14
|
+
Object.defineProperty(exports, "LoggerKey", { enumerable: true, get: function () { return logger_1.LoggerKey; } });
|
|
15
|
+
var loggerService_1 = require("./logger/domain/loggerService");
|
|
16
|
+
Object.defineProperty(exports, "LoggerService", { enumerable: true, get: function () { return __importDefault(loggerService_1).default; } });
|
|
17
|
+
var contextStorageService_1 = require("./context/domain/interfaces/contextStorageService");
|
|
18
|
+
Object.defineProperty(exports, "ContextStorageServiceKey", { enumerable: true, get: function () { return contextStorageService_1.ContextStorageServiceKey; } });
|
|
19
|
+
var loggerTransport_1 = require("./logger/domain/loggerTransport");
|
|
20
|
+
Object.defineProperty(exports, "LoggerTransportKey", { enumerable: true, get: function () { return loggerTransport_1.LoggerTransportKey; } });
|
|
21
|
+
var normalizedLog_1 = require("./logger/domain/normalizedLog");
|
|
22
|
+
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return normalizedLog_1.serializeError; } });
|
|
23
|
+
var log_1 = require("./logger/domain/log");
|
|
24
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return log_1.LogLevel; } });
|
|
25
|
+
var winstonTransportAdapter_1 = require("./logger/infrastructure/winston/winstonTransportAdapter");
|
|
26
|
+
Object.defineProperty(exports, "WinstonTransportAdapter", { enumerable: true, get: function () { return winstonTransportAdapter_1.WinstonTransportAdapter; } });
|
|
27
|
+
Object.defineProperty(exports, "WinstonTransportAdapterTransportsKey", { enumerable: true, get: function () { return winstonTransportAdapter_1.WinstonTransportAdapterTransportsKey; } });
|
|
28
|
+
var centralLogForwarder_1 = require("./logger/infrastructure/forwarding/centralLogForwarder");
|
|
29
|
+
Object.defineProperty(exports, "CentralLogForwarderKey", { enumerable: true, get: function () { return centralLogForwarder_1.CentralLogForwarderKey; } });
|
|
30
|
+
Object.defineProperty(exports, "KafkaProducerKey", { enumerable: true, get: function () { return centralLogForwarder_1.KafkaProducerKey; } });
|
|
31
|
+
var centralLogForwarder_2 = require("./logger/infrastructure/forwarding/centralLogForwarder");
|
|
32
|
+
Object.defineProperty(exports, "CentralLogForwarder", { enumerable: true, get: function () { return centralLogForwarder_2.CentralLogForwarder; } });
|
|
33
|
+
var kafkaCentralLogForwarder_1 = require("./logger/infrastructure/forwarding/kafkaCentralLogForwarder");
|
|
34
|
+
Object.defineProperty(exports, "KafkaCentralLogForwarder", { enumerable: true, get: function () { return kafkaCentralLogForwarder_1.KafkaCentralLogForwarder; } });
|
|
35
|
+
var httpCentralLogForwarder_1 = require("./logger/infrastructure/forwarding/httpCentralLogForwarder");
|
|
36
|
+
Object.defineProperty(exports, "HttpCentralLogForwarder", { enumerable: true, get: function () { return httpCentralLogForwarder_1.HttpCentralLogForwarder; } });
|
|
13
37
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/src/index.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA8E;AAArE,8GAAA,aAAa,OAAA;AACtB,4EAA+F;AAAtF,4GAAA,YAAY,OAAA;AACrB,wGAAkH;AAAzG,yJAAA,OAAO,OAA8B;AAE9C,iDAAmD;AAA1C,mGAAA,SAAS,OAAA;AAGlB,+DAAyE;AAAhE,+HAAA,OAAO,OAAiB;AAEjC,2FAA6F;AAApF,iIAAA,wBAAwB,OAAA;AAGjC,mEAAsF;AAA5D,qHAAA,kBAAkB,OAAA;AAE5C,+DAA+D;AAAtD,+GAAA,cAAc,OAAA;AAEvB,2CAA+C;AAAtC,+FAAA,QAAQ,OAAA;AAGjB,mGAGiE;AAF7D,kIAAA,uBAAuB,OAAA;AACvB,+IAAA,oCAAoC,OAAA;AAGxC,8FAGgE;AAF5D,6HAAA,sBAAsB,OAAA;AACtB,uHAAA,gBAAgB,OAAA;AAGpB,8FAA6F;AAApF,0HAAA,mBAAmB,OAAA;AAC5B,wGAAuG;AAA9F,oIAAA,wBAAwB,OAAA;AACjC,sGAAqG;AAA5F,kIAAA,uBAAuB,OAAA"}
|
package/logger/domain/log.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export interface Log {
|
|
|
12
12
|
message: string;
|
|
13
13
|
data: LogData;
|
|
14
14
|
}
|
|
15
|
+
import { SerializedError } from './normalizedLog';
|
|
15
16
|
export interface LogData {
|
|
16
17
|
organization?: string;
|
|
17
18
|
context?: string;
|
|
18
19
|
app?: string;
|
|
19
20
|
sourceClass?: string;
|
|
20
21
|
correlationId?: string;
|
|
21
|
-
error?:
|
|
22
|
+
error?: SerializedError;
|
|
22
23
|
props?: NodeJS.Dict<any>;
|
|
24
|
+
durationMs?: number;
|
|
23
25
|
}
|
|
@@ -2,22 +2,27 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import ContextStorageService from '../../context/domain/interfaces/contextStorageService';
|
|
3
3
|
import { LogData, LogLevel } from '../../logger/domain/log';
|
|
4
4
|
import Logger from '../../logger/domain/logger';
|
|
5
|
+
import { LoggerTransport } from '../../logger/domain/loggerTransport';
|
|
6
|
+
import { ICentralLogForwarder } from '../../logger/infrastructure/forwarding/centralLogForwarder';
|
|
5
7
|
export default class LoggerService implements Logger {
|
|
6
|
-
private
|
|
8
|
+
private transports;
|
|
7
9
|
private contextStorageService;
|
|
8
10
|
private configService;
|
|
9
11
|
private sourceClass;
|
|
10
12
|
private organization;
|
|
11
13
|
private context;
|
|
12
14
|
private app;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
private centralLogForwarder;
|
|
16
|
+
constructor(transports: LoggerTransport[], parentClass: object, contextStorageService: ContextStorageService, configService: ConfigService, centralLogForwarder?: ICentralLogForwarder);
|
|
17
|
+
log(level: LogLevel, message: string | Error, data?: LogData, _profile?: string): void;
|
|
15
18
|
debug(message: string, data?: LogData, profile?: string): void;
|
|
16
19
|
info(message: string, data?: LogData, profile?: string): void;
|
|
17
20
|
warn(message: string | Error, data?: LogData, profile?: string): void;
|
|
18
21
|
error(message: string | Error, data?: LogData, profile?: string): void;
|
|
19
22
|
fatal(message: string | Error, data?: LogData, profile?: string): void;
|
|
20
23
|
emergency(message: string | Error, data?: LogData, profile?: string): void;
|
|
24
|
+
startProfile(_id: string): void;
|
|
25
|
+
private normalizeLog;
|
|
26
|
+
private sendToTransports;
|
|
21
27
|
private getLogData;
|
|
22
|
-
startProfile(id: string): void;
|
|
23
28
|
}
|
|
@@ -16,68 +16,190 @@ const common_1 = require("@nestjs/common");
|
|
|
16
16
|
const config_1 = require("@nestjs/config");
|
|
17
17
|
const core_1 = require("@nestjs/core");
|
|
18
18
|
const contextStorageService_1 = require("../../context/domain/interfaces/contextStorageService");
|
|
19
|
-
const
|
|
19
|
+
const log_1 = require("../../logger/domain/log");
|
|
20
|
+
const loggerTransport_1 = require("../../logger/domain/loggerTransport");
|
|
21
|
+
const normalizedLog_1 = require("../../logger/domain/normalizedLog");
|
|
22
|
+
const centralLogForwarder_1 = require("../../logger/infrastructure/forwarding/centralLogForwarder");
|
|
20
23
|
let LoggerService = class LoggerService {
|
|
21
|
-
|
|
24
|
+
transports;
|
|
22
25
|
contextStorageService;
|
|
23
26
|
configService;
|
|
24
27
|
sourceClass;
|
|
25
28
|
organization;
|
|
26
29
|
context;
|
|
27
30
|
app;
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
centralLogForwarder = null;
|
|
32
|
+
constructor(transports, parentClass, contextStorageService, configService, centralLogForwarder) {
|
|
33
|
+
this.transports = transports;
|
|
30
34
|
this.contextStorageService = contextStorageService;
|
|
31
35
|
this.configService = configService;
|
|
36
|
+
this.centralLogForwarder = centralLogForwarder || null;
|
|
32
37
|
this.sourceClass = parentClass?.constructor?.name;
|
|
33
|
-
|
|
34
|
-
infer: true
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
try {
|
|
39
|
+
const config = this.configService.get('logger', { infer: true });
|
|
40
|
+
this.organization = config?.organization;
|
|
41
|
+
this.context = config?.context;
|
|
42
|
+
this.app = config?.app;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
this.organization = undefined;
|
|
46
|
+
this.context = undefined;
|
|
47
|
+
this.app = undefined;
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
|
-
log(level, message, data,
|
|
41
|
-
|
|
50
|
+
log(level, message, data, _profile) {
|
|
51
|
+
try {
|
|
52
|
+
const normalizedLog = this.normalizeLog(level, message, data);
|
|
53
|
+
this.sendToTransports(normalizedLog);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('LoggerService log error (swallowed):', error);
|
|
57
|
+
}
|
|
42
58
|
}
|
|
43
59
|
debug(message, data, profile) {
|
|
44
|
-
|
|
60
|
+
try {
|
|
61
|
+
this.log(log_1.LogLevel.Debug, message, data, profile);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error('LoggerService debug error (swallowed):', error);
|
|
65
|
+
}
|
|
45
66
|
}
|
|
46
67
|
info(message, data, profile) {
|
|
47
|
-
|
|
68
|
+
try {
|
|
69
|
+
this.log(log_1.LogLevel.Info, message, data, profile);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('LoggerService info error (swallowed):', error);
|
|
73
|
+
}
|
|
48
74
|
}
|
|
49
75
|
warn(message, data, profile) {
|
|
50
|
-
|
|
76
|
+
try {
|
|
77
|
+
this.log(log_1.LogLevel.Warn, message, data, profile);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('LoggerService warn error (swallowed):', error);
|
|
81
|
+
}
|
|
51
82
|
}
|
|
52
83
|
error(message, data, profile) {
|
|
53
|
-
|
|
84
|
+
try {
|
|
85
|
+
this.log(log_1.LogLevel.Error, message, data, profile);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error('LoggerService error (swallowed):', error);
|
|
89
|
+
}
|
|
54
90
|
}
|
|
55
91
|
fatal(message, data, profile) {
|
|
56
|
-
|
|
92
|
+
try {
|
|
93
|
+
this.log(log_1.LogLevel.Fatal, message, data, profile);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error('LoggerService fatal error (swallowed):', error);
|
|
97
|
+
}
|
|
57
98
|
}
|
|
58
99
|
emergency(message, data, profile) {
|
|
59
|
-
|
|
100
|
+
try {
|
|
101
|
+
this.log(log_1.LogLevel.Emergency, message, data, profile);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error('LoggerService emergency error (swallowed):', error);
|
|
105
|
+
}
|
|
60
106
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
107
|
+
startProfile(_id) {
|
|
108
|
+
try {
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('LoggerService startProfile error (swallowed):', error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
normalizeLog(level, message, data) {
|
|
115
|
+
try {
|
|
116
|
+
const logData = this.getLogData(data);
|
|
117
|
+
let error = logData?.error;
|
|
118
|
+
if (message instanceof Error) {
|
|
119
|
+
error = (0, normalizedLog_1.serializeError)(message);
|
|
120
|
+
}
|
|
121
|
+
else if (logData?.error) {
|
|
122
|
+
error =
|
|
123
|
+
logData.error instanceof Error ? (0, normalizedLog_1.serializeError)(logData.error) : logData.error;
|
|
124
|
+
}
|
|
125
|
+
const normalizedLog = {
|
|
126
|
+
timestamp: Date.now(),
|
|
127
|
+
level: level,
|
|
128
|
+
message: message instanceof Error ? message.message : message,
|
|
129
|
+
organization: logData?.organization,
|
|
130
|
+
context: logData?.context,
|
|
131
|
+
app: logData?.app,
|
|
132
|
+
sourceClass: logData?.sourceClass,
|
|
133
|
+
correlationId: logData?.correlationId,
|
|
134
|
+
error: error,
|
|
135
|
+
props: logData?.props,
|
|
136
|
+
durationMs: logData?.durationMs,
|
|
137
|
+
label: logData?.organization && logData?.context && logData?.app
|
|
138
|
+
? `${logData.organization}.${logData.context}.${logData.app}`
|
|
139
|
+
: undefined,
|
|
140
|
+
stack: error?.stack,
|
|
141
|
+
};
|
|
142
|
+
return normalizedLog;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('LoggerService normalizeLog error (swallowed):', error);
|
|
146
|
+
return {
|
|
147
|
+
timestamp: Date.now(),
|
|
148
|
+
level: level,
|
|
149
|
+
message: message instanceof Error ? message.message : String(message),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
70
152
|
}
|
|
71
|
-
|
|
72
|
-
|
|
153
|
+
sendToTransports(normalizedLog) {
|
|
154
|
+
try {
|
|
155
|
+
for (const transport of this.transports) {
|
|
156
|
+
try {
|
|
157
|
+
transport.log(normalizedLog);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error(`Transport error (swallowed):`, error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (this.centralLogForwarder) {
|
|
164
|
+
try {
|
|
165
|
+
this.centralLogForwarder.forward(normalizedLog);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error('CentralLogForwarder error (swallowed):', error);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error('LoggerService sendToTransports error (swallowed):', error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
getLogData(data) {
|
|
177
|
+
try {
|
|
178
|
+
return {
|
|
179
|
+
...data,
|
|
180
|
+
organization: data?.organization || this.organization,
|
|
181
|
+
context: data?.context || this.context,
|
|
182
|
+
app: data?.app || this.app,
|
|
183
|
+
sourceClass: data?.sourceClass || this.sourceClass,
|
|
184
|
+
correlationId: data?.correlationId || this.contextStorageService.getContextId(),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
console.error('LoggerService getLogData error (swallowed):', error);
|
|
189
|
+
return {
|
|
190
|
+
...data,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
73
193
|
}
|
|
74
194
|
};
|
|
75
195
|
LoggerService = __decorate([
|
|
76
196
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
77
|
-
__param(0, (0, common_1.Inject)(
|
|
197
|
+
__param(0, (0, common_1.Inject)(loggerTransport_1.LoggerTransportKey)),
|
|
78
198
|
__param(1, (0, common_1.Inject)(core_1.INQUIRER)),
|
|
79
199
|
__param(2, (0, common_1.Inject)(contextStorageService_1.ContextStorageServiceKey)),
|
|
80
|
-
|
|
200
|
+
__param(4, (0, common_1.Optional)()),
|
|
201
|
+
__param(4, (0, common_1.Inject)(centralLogForwarder_1.CentralLogForwarderKey)),
|
|
202
|
+
__metadata("design:paramtypes", [Array, Object, Object, config_1.ConfigService, Object])
|
|
81
203
|
], LoggerService);
|
|
82
204
|
exports.default = LoggerService;
|
|
83
205
|
//# sourceMappingURL=loggerService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerService.js","sourceRoot":"","sources":["../../../../libs/src/logger/domain/loggerService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"loggerService.js","sourceRoot":"","sources":["../../../../libs/src/logger/domain/loggerService.ts"],"names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AAK,CAAC,CAAC;YACpE,OAAO;gBACH,GAAG,IAAI;aACV,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AA/MoB,aAAa;IADjC,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;IAS9B,WAAA,IAAA,eAAM,EAAC,oCAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,eAAQ,CAAC,CAAA;IAChB,WAAA,IAAA,eAAM,EAAC,gDAAwB,CAAC,CAAA;IAGhC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,4CAAsB,CAAC,CAAA;4DADpB,sBAAa;GAZvB,aAAa,CA+MjC;kBA/MoB,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loggerTransport.js","sourceRoot":"","sources":["../../../../libs/src/logger/domain/loggerTransport.ts"],"names":[],"mappings":";;;AAKa,QAAA,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LogLevel } from './log';
|
|
2
|
+
export interface SerializedError {
|
|
3
|
+
name: string;
|
|
4
|
+
message: string;
|
|
5
|
+
stack?: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export interface NormalizedLog {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
level: LogLevel;
|
|
11
|
+
message: string;
|
|
12
|
+
organization?: string;
|
|
13
|
+
context?: string;
|
|
14
|
+
app?: string;
|
|
15
|
+
sourceClass?: string;
|
|
16
|
+
correlationId?: string;
|
|
17
|
+
error?: SerializedError;
|
|
18
|
+
props?: Record<string, any>;
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
label?: string;
|
|
21
|
+
stack?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function serializeError(error: Error | unknown): SerializedError | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeError = serializeError;
|
|
4
|
+
function serializeError(error) {
|
|
5
|
+
if (!error) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (error instanceof Error) {
|
|
9
|
+
const serialized = {
|
|
10
|
+
name: error.name,
|
|
11
|
+
message: error.message,
|
|
12
|
+
};
|
|
13
|
+
if (error.stack) {
|
|
14
|
+
serialized.stack = error.stack;
|
|
15
|
+
}
|
|
16
|
+
Object.keys(error).forEach((key) => {
|
|
17
|
+
if (key !== 'name' && key !== 'message' && key !== 'stack') {
|
|
18
|
+
try {
|
|
19
|
+
serialized[key] = error[key];
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return serialized;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return {
|
|
29
|
+
name: 'UnknownError',
|
|
30
|
+
message: String(error),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=normalizedLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizedLog.js","sourceRoot":"","sources":["../../../../libs/src/logger/domain/normalizedLog.ts"],"names":[],"mappings":";;AAoCA,wCAsCC;AAtCD,SAAgB,cAAc,CAAC,KAAsB;IACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,GAAoB;YAChC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;SACzB,CAAC;QAEF,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACnC,CAAC;QAGD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/B,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;gBACzD,IAAI,CAAC;oBACD,UAAU,CAAC,GAAG,CAAC,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;gBAC1C,CAAC;gBAAC,MAAM,CAAC;gBAET,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACtB,CAAC;IAGD,IAAI,CAAC;QACD,OAAO;YACH,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;SACzB,CAAC;IACN,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,SAAS,CAAC;IACrB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { NormalizedLog } from '../../domain/normalizedLog';
|
|
3
|
+
export declare const KafkaProducerKey: unique symbol;
|
|
4
|
+
export declare const CentralLogForwarderKey: unique symbol;
|
|
5
|
+
export interface ICentralLogForwarder {
|
|
6
|
+
forward(normalizedLog: NormalizedLog): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class CentralLogForwarder implements ICentralLogForwarder {
|
|
9
|
+
private readonly configService;
|
|
10
|
+
private kafkaProducer?;
|
|
11
|
+
private forwarder;
|
|
12
|
+
constructor(configService: ConfigService, kafkaProducer?: any);
|
|
13
|
+
forward(normalizedLog: NormalizedLog): void;
|
|
14
|
+
private parseBoolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CentralLogForwarder = exports.CentralLogForwarderKey = exports.KafkaProducerKey = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const config_1 = require("@nestjs/config");
|
|
18
|
+
const kafkaCentralLogForwarder_1 = require("./kafkaCentralLogForwarder");
|
|
19
|
+
const httpCentralLogForwarder_1 = require("./httpCentralLogForwarder");
|
|
20
|
+
exports.KafkaProducerKey = Symbol('KafkaProducer');
|
|
21
|
+
exports.CentralLogForwarderKey = Symbol('CentralLogForwarder');
|
|
22
|
+
let CentralLogForwarder = class CentralLogForwarder {
|
|
23
|
+
configService;
|
|
24
|
+
kafkaProducer;
|
|
25
|
+
forwarder = null;
|
|
26
|
+
constructor(configService, kafkaProducer) {
|
|
27
|
+
this.configService = configService;
|
|
28
|
+
this.kafkaProducer = kafkaProducer;
|
|
29
|
+
try {
|
|
30
|
+
const config = this.configService.get('logger', { infer: true });
|
|
31
|
+
const forwardToCentral = this.parseBoolean(config?.forwardToCentral);
|
|
32
|
+
const transportType = config?.transportType;
|
|
33
|
+
if (forwardToCentral) {
|
|
34
|
+
if (transportType === 'kafka') {
|
|
35
|
+
const kafkaTopic = config?.kafkaTopic;
|
|
36
|
+
if (kafkaTopic) {
|
|
37
|
+
this.forwarder = new kafkaCentralLogForwarder_1.KafkaCentralLogForwarder(kafkaTopic, this.kafkaProducer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (transportType === 'http') {
|
|
41
|
+
const httpEndpoint = config?.httpEndpoint;
|
|
42
|
+
if (httpEndpoint) {
|
|
43
|
+
this.forwarder = new httpCentralLogForwarder_1.HttpCentralLogForwarder(httpEndpoint);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('CentralLogForwarder initialization error (swallowed):', error);
|
|
50
|
+
this.forwarder = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
forward(normalizedLog) {
|
|
54
|
+
if (!this.forwarder) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
this.forwarder.forward(normalizedLog);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error('CentralLogForwarder forward error (swallowed):', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
parseBoolean(value) {
|
|
65
|
+
if (value === undefined) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === 'boolean') {
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
return value === 'true' || value === '1';
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.CentralLogForwarder = CentralLogForwarder;
|
|
75
|
+
exports.CentralLogForwarder = CentralLogForwarder = __decorate([
|
|
76
|
+
(0, common_1.Injectable)(),
|
|
77
|
+
__param(1, (0, common_1.Optional)()),
|
|
78
|
+
__param(1, (0, common_1.Inject)(exports.KafkaProducerKey)),
|
|
79
|
+
__metadata("design:paramtypes", [config_1.ConfigService, Object])
|
|
80
|
+
], CentralLogForwarder);
|
|
81
|
+
//# sourceMappingURL=centralLogForwarder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"centralLogForwarder.js","sourceRoot":"","sources":["../../../../../libs/src/logger/infrastructure/forwarding/centralLogForwarder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,2CAA+C;AAG/C,yEAAsE;AACtE,uEAAoE;AAMvD,QAAA,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAK3C,QAAA,sBAAsB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAoB7D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAIP;IAC6B;IAJ1C,SAAS,GAAgC,IAAI,CAAC;IAEtD,YACqB,aAA4B,EACC,aAAmB;QADhD,kBAAa,GAAb,aAAa,CAAe;QACC,kBAAa,GAAb,aAAa,CAAM;QAEjE,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAQ,CAAC;YACxE,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACrE,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,CAAC;YAE5C,IAAI,gBAAgB,EAAE,CAAC;gBACnB,IAAI,aAAa,KAAK,OAAO,EAAE,CAAC;oBAC5B,MAAM,UAAU,GAAG,MAAM,EAAE,UAAU,CAAC;oBACtC,IAAI,UAAU,EAAE,CAAC;wBACb,IAAI,CAAC,SAAS,GAAG,IAAI,mDAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;oBAClF,CAAC;gBACL,CAAC;qBAAM,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;oBAClC,MAAM,YAAY,GAAG,MAAM,EAAE,YAAY,CAAC;oBAC1C,IAAI,YAAY,EAAE,CAAC;wBACf,IAAI,CAAC,SAAS,GAAG,IAAI,iDAAuB,CAAC,YAAY,CAAC,CAAC;oBAC/D,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEb,OAAO,CAAC,KAAK,CAAC,uDAAuD,EAAE,KAAK,CAAC,CAAC;YAC9E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;IACL,CAAC;IAMM,OAAO,CAAC,aAA4B;QACvC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,OAAO;QACX,CAAC;QAED,IAAI,CAAC;YACD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEb,OAAO,CAAC,KAAK,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,KAAmC;QACpD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG,CAAC;IAC7C,CAAC;CACJ,CAAA;AA1DY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAMJ,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,wBAAgB,CAAC,CAAA;qCADL,sBAAa;GAJxC,mBAAmB,CA0D/B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NormalizedLog } from '../../domain/normalizedLog';
|
|
2
|
+
import { ICentralLogForwarder } from './centralLogForwarder';
|
|
3
|
+
export declare class HttpCentralLogForwarder implements ICentralLogForwarder {
|
|
4
|
+
private readonly endpoint;
|
|
5
|
+
private readonly url;
|
|
6
|
+
constructor(endpoint: string);
|
|
7
|
+
forward(normalizedLog: NormalizedLog): void;
|
|
8
|
+
}
|