logiscout 1.0.3 → 1.0.4
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 +193 -1
- package/dist/cjs/api/Interceptor.cjs +66 -7
- package/dist/cjs/api/Interceptor.d.ts +4 -3
- package/dist/cjs/api/Interceptor.d.ts.map +1 -1
- package/dist/cjs/api/LogApi.cjs +2 -6
- package/dist/cjs/api/LogApi.d.ts +2 -3
- package/dist/cjs/api/LogApi.d.ts.map +1 -1
- package/dist/cjs/core/constants/Levels/LevelsColors.cjs +11 -0
- package/dist/cjs/core/constants/Levels/LevelsColors.d.ts +3 -0
- package/dist/cjs/core/constants/Levels/LevelsColors.d.ts.map +1 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.cjs +11 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.d.ts +3 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.d.ts.map +1 -0
- package/dist/cjs/core/context/RequestContext.cjs +4 -14
- package/dist/cjs/core/context/RequestContext.d.ts +0 -3
- package/dist/cjs/core/context/RequestContext.d.ts.map +1 -1
- package/dist/cjs/core/enum/LogPayLoads.cjs +8 -0
- package/dist/cjs/core/enum/LogPayLoads.d.ts +5 -0
- package/dist/cjs/core/enum/LogPayLoads.d.ts.map +1 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.cjs +18 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.d.ts +3 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.d.ts.map +1 -0
- package/dist/cjs/core/interface/CorrelationSession.cjs +2 -0
- package/dist/cjs/core/interface/CorrelationSession.d.ts +32 -0
- package/dist/cjs/core/interface/CorrelationSession.d.ts.map +1 -0
- package/dist/cjs/core/interface/JsonzierConfig.cjs +2 -0
- package/dist/cjs/core/interface/JsonzierConfig.d.ts +6 -0
- package/dist/cjs/core/interface/JsonzierConfig.d.ts.map +1 -0
- package/dist/cjs/core/interface/RequestContext.cjs +2 -0
- package/dist/cjs/core/interface/RequestContext.d.ts +4 -0
- package/dist/cjs/core/interface/RequestContext.d.ts.map +1 -0
- package/dist/cjs/core/interface/payloads/Payloads.cjs +2 -0
- package/dist/cjs/core/interface/payloads/Payloads.d.ts +11 -0
- package/dist/cjs/core/interface/payloads/Payloads.d.ts.map +1 -0
- package/dist/cjs/core/store/CorrelationStore.cjs +29 -0
- package/dist/cjs/core/store/CorrelationStore.d.ts +5 -0
- package/dist/cjs/core/store/CorrelationStore.d.ts.map +1 -0
- package/dist/cjs/errors/ThrowError.cjs +6 -0
- package/dist/cjs/errors/ThrowError.d.ts +2 -0
- package/dist/cjs/errors/ThrowError.d.ts.map +1 -0
- package/dist/cjs/middlewares/correlationMiddleware.cjs +28 -64
- package/dist/cjs/middlewares/correlationMiddleware.d.ts +1 -16
- package/dist/cjs/middlewares/correlationMiddleware.d.ts.map +1 -1
- package/dist/cjs/services/Levels/Levels.cjs +10 -10
- package/dist/cjs/services/Levels/Levels.d.ts +15 -5
- package/dist/cjs/services/Levels/Levels.d.ts.map +1 -1
- package/dist/cjs/services/Logger/Logger.cjs +51 -134
- package/dist/cjs/services/Logger/Logger.d.ts +6 -1
- package/dist/cjs/services/Logger/Logger.d.ts.map +1 -1
- package/dist/cjs/services/formatters/ConsoleFormatter.cjs +2 -9
- package/dist/cjs/services/formatters/ConsoleFormatter.d.ts.map +1 -1
- package/dist/cjs/services/processors/Jsonizer.cjs +31 -0
- package/dist/cjs/services/processors/Jsonizer.d.ts +11 -0
- package/dist/cjs/services/processors/Jsonizer.d.ts.map +1 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.cjs +16 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.d.ts +5 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.d.ts.map +1 -0
- package/dist/cjs/services/transporter/ServerTransporter.cjs +31 -0
- package/dist/cjs/services/transporter/ServerTransporter.d.ts +10 -0
- package/dist/cjs/services/transporter/ServerTransporter.d.ts.map +1 -0
- package/dist/cjs/utils/GenerateCorrelationId.cjs +10 -0
- package/dist/cjs/utils/GenerateCorrelationId.d.ts +2 -0
- package/dist/cjs/utils/GenerateCorrelationId.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateComponentName.cjs +14 -0
- package/dist/cjs/validator/ValidateComponentName.d.ts +2 -0
- package/dist/cjs/validator/ValidateComponentName.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogEntry.cjs +18 -0
- package/dist/cjs/validator/ValidateLogEntry.d.ts +3 -0
- package/dist/cjs/validator/ValidateLogEntry.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogLevel.cjs +11 -0
- package/dist/cjs/validator/ValidateLogLevel.d.ts +2 -0
- package/dist/cjs/validator/ValidateLogLevel.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogMessage.cjs +10 -0
- package/dist/cjs/validator/ValidateLogMessage.d.ts +2 -0
- package/dist/cjs/validator/ValidateLogMessage.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateRequestContext.cjs +18 -0
- package/dist/cjs/validator/ValidateRequestContext.d.ts +2 -0
- package/dist/cjs/validator/ValidateRequestContext.d.ts.map +1 -0
- package/dist/esm/api/Interceptor.d.ts +4 -3
- package/dist/esm/api/Interceptor.d.ts.map +1 -1
- package/dist/esm/api/Interceptor.js +64 -7
- package/dist/esm/api/LogApi.d.ts +2 -3
- package/dist/esm/api/LogApi.d.ts.map +1 -1
- package/dist/esm/api/LogApi.js +2 -3
- package/dist/esm/core/constants/Levels/LevelsColors.d.ts +3 -0
- package/dist/esm/core/constants/Levels/LevelsColors.d.ts.map +1 -0
- package/dist/esm/core/constants/Levels/LevelsColors.js +8 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.d.ts +3 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.d.ts.map +1 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.js +8 -0
- package/dist/esm/core/context/RequestContext.d.ts +0 -3
- package/dist/esm/core/context/RequestContext.d.ts.map +1 -1
- package/dist/esm/core/context/RequestContext.js +4 -14
- package/dist/esm/core/enum/LogPayLoads.d.ts +5 -0
- package/dist/esm/core/enum/LogPayLoads.d.ts.map +1 -0
- package/dist/esm/core/enum/LogPayLoads.js +5 -0
- package/dist/esm/core/formatters/winston/FormatLogs.d.ts +3 -0
- package/dist/esm/core/formatters/winston/FormatLogs.d.ts.map +1 -0
- package/dist/esm/core/formatters/winston/FormatLogs.js +15 -0
- package/dist/esm/core/interface/CorrelationSession.d.ts +32 -0
- package/dist/esm/core/interface/CorrelationSession.d.ts.map +1 -0
- package/dist/esm/core/interface/CorrelationSession.js +1 -0
- package/dist/esm/core/interface/JsonzierConfig.d.ts +6 -0
- package/dist/esm/core/interface/JsonzierConfig.d.ts.map +1 -0
- package/dist/esm/core/interface/JsonzierConfig.js +1 -0
- package/dist/esm/core/interface/RequestContext.d.ts +4 -0
- package/dist/esm/core/interface/RequestContext.d.ts.map +1 -0
- package/dist/esm/core/interface/RequestContext.js +1 -0
- package/dist/esm/core/interface/payloads/Payloads.d.ts +11 -0
- package/dist/esm/core/interface/payloads/Payloads.d.ts.map +1 -0
- package/dist/esm/core/interface/payloads/Payloads.js +1 -0
- package/dist/esm/core/store/CorrelationStore.d.ts +5 -0
- package/dist/esm/core/store/CorrelationStore.d.ts.map +1 -0
- package/dist/esm/core/store/CorrelationStore.js +24 -0
- package/dist/esm/errors/ThrowError.d.ts +2 -0
- package/dist/esm/errors/ThrowError.d.ts.map +1 -0
- package/dist/esm/errors/ThrowError.js +3 -0
- package/dist/esm/middlewares/correlationMiddleware.d.ts +1 -16
- package/dist/esm/middlewares/correlationMiddleware.d.ts.map +1 -1
- package/dist/esm/middlewares/correlationMiddleware.js +27 -59
- package/dist/esm/services/Levels/Levels.d.ts +15 -5
- package/dist/esm/services/Levels/Levels.d.ts.map +1 -1
- package/dist/esm/services/Levels/Levels.js +10 -10
- package/dist/esm/services/Logger/Logger.d.ts +6 -1
- package/dist/esm/services/Logger/Logger.d.ts.map +1 -1
- package/dist/esm/services/Logger/Logger.js +48 -101
- package/dist/esm/services/formatters/ConsoleFormatter.d.ts.map +1 -1
- package/dist/esm/services/formatters/ConsoleFormatter.js +1 -8
- package/dist/esm/services/processors/Jsonizer.d.ts +11 -0
- package/dist/esm/services/processors/Jsonizer.d.ts.map +1 -0
- package/dist/esm/services/processors/Jsonizer.js +27 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.d.ts +5 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.d.ts.map +1 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.js +9 -0
- package/dist/esm/services/transporter/ServerTransporter.d.ts +10 -0
- package/dist/esm/services/transporter/ServerTransporter.d.ts.map +1 -0
- package/dist/esm/services/transporter/ServerTransporter.js +27 -0
- package/dist/esm/utils/GenerateCorrelationId.d.ts +2 -0
- package/dist/esm/utils/GenerateCorrelationId.d.ts.map +1 -0
- package/dist/esm/utils/GenerateCorrelationId.js +4 -0
- package/dist/esm/validator/ValidateComponentName.d.ts +2 -0
- package/dist/esm/validator/ValidateComponentName.d.ts.map +1 -0
- package/dist/esm/validator/ValidateComponentName.js +11 -0
- package/dist/esm/validator/ValidateLogEntry.d.ts +3 -0
- package/dist/esm/validator/ValidateLogEntry.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogEntry.js +15 -0
- package/dist/esm/validator/ValidateLogLevel.d.ts +2 -0
- package/dist/esm/validator/ValidateLogLevel.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogLevel.js +8 -0
- package/dist/esm/validator/ValidateLogMessage.d.ts +2 -0
- package/dist/esm/validator/ValidateLogMessage.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogMessage.js +7 -0
- package/dist/esm/validator/ValidateRequestContext.d.ts +2 -0
- package/dist/esm/validator/ValidateRequestContext.d.ts.map +1 -0
- package/dist/esm/validator/ValidateRequestContext.js +15 -0
- package/package.json +1 -1
|
@@ -1,63 +1,31 @@
|
|
|
1
1
|
import { RequestContext } from "../core/context/RequestContext.js";
|
|
2
|
-
import
|
|
2
|
+
import { endSession, getOrCreateSession, removeSession, } from "../core/store/CorrelationStore.js";
|
|
3
3
|
import { getLogiScouConfig } from "../initiator/state.js";
|
|
4
|
-
|
|
4
|
+
import { ServerTransporter } from "../services/transporter/ServerTransporter.js";
|
|
5
|
+
const serverTransporter = new ServerTransporter();
|
|
6
|
+
export function createCorrelationMiddleware() {
|
|
5
7
|
return (req, res, next) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const correlationId = (typeof existingId === "string" && existingId.trim()) || crypto.randomUUID();
|
|
29
|
-
// Validate correlation ID
|
|
30
|
-
if (!correlationId || typeof correlationId !== "string") {
|
|
31
|
-
console.error("[CorrelationMiddleware] Error: Failed to generate or retrieve correlation ID");
|
|
32
|
-
next?.(new Error("Correlation ID generation failed"));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (correlationId.length > 100) {
|
|
36
|
-
console.warn("[CorrelationMiddleware] Warning: Correlation ID exceeds 100 characters and will be truncated");
|
|
37
|
-
}
|
|
38
|
-
// Run the remaining middleware in the request context
|
|
39
|
-
RequestContext.run(() => {
|
|
40
|
-
// Safely set the correlation ID header
|
|
41
|
-
try {
|
|
42
|
-
if (res.setHeader) {
|
|
43
|
-
res.setHeader("x-correlation-id", correlationId);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (headerError) {
|
|
47
|
-
// setHeader might fail in some edge cases, don't block the request
|
|
48
|
-
console.warn("[CorrelationMiddleware] Warning: Could not set x-correlation-id header", headerError instanceof Error ? headerError.message : "Unknown error");
|
|
49
|
-
}
|
|
50
|
-
// Store correlation ID in response locals for downstream access
|
|
51
|
-
if (res.locals) {
|
|
52
|
-
res.locals.correlationId = correlationId;
|
|
53
|
-
}
|
|
54
|
-
next?.();
|
|
55
|
-
}, correlationId);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
59
|
-
console.error(`[CorrelationMiddleware] Error: Failed to initialize request context. ${errorMessage}`);
|
|
60
|
-
next?.(error instanceof Error ? error : new Error("Request context initialization failed"));
|
|
61
|
-
}
|
|
8
|
+
const correlationId = req.headers["x-correlation-id"] ?? crypto.randomUUID();
|
|
9
|
+
RequestContext.run(() => {
|
|
10
|
+
const session = getOrCreateSession(correlationId, {
|
|
11
|
+
projectName: getLogiScouConfig().projectName,
|
|
12
|
+
environment: getLogiScouConfig().environment,
|
|
13
|
+
correlationId,
|
|
14
|
+
request: {
|
|
15
|
+
method: req.method,
|
|
16
|
+
path: req.originalUrl || req.url,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
res.setHeader("x-correlation-id", correlationId);
|
|
20
|
+
console.log("----- SENDING TO THE SERVER-----------");
|
|
21
|
+
res.on("finish", () => {
|
|
22
|
+
session.request.statusCode = res.statusCode;
|
|
23
|
+
const payload = endSession(correlationId);
|
|
24
|
+
if (payload)
|
|
25
|
+
serverTransporter.transport(payload);
|
|
26
|
+
removeSession(correlationId);
|
|
27
|
+
});
|
|
28
|
+
next();
|
|
29
|
+
}, correlationId);
|
|
62
30
|
};
|
|
63
|
-
}
|
|
31
|
+
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { Logger } from "../Logger/Logger.js";
|
|
2
2
|
import { LoggerInterface } from "../../core/interface/LoggerInterface.js";
|
|
3
3
|
export declare class Levels extends Logger implements LoggerInterface {
|
|
4
|
-
info(message: string, meta?: Record<string, unknown
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
info(message: string, meta?: Record<string, unknown>, options?: {
|
|
5
|
+
send?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
warn(message: string, meta?: Record<string, unknown>, options?: {
|
|
8
|
+
send?: boolean;
|
|
9
|
+
}): void;
|
|
10
|
+
error(message: string, meta?: Record<string, unknown>, options?: {
|
|
11
|
+
send?: boolean;
|
|
12
|
+
}): void;
|
|
13
|
+
debug(message: string, meta?: Record<string, unknown>, options?: {
|
|
14
|
+
send?: boolean;
|
|
15
|
+
}): void;
|
|
16
|
+
critical(message: string, meta?: Record<string, unknown>, options?: {
|
|
17
|
+
send?: boolean;
|
|
18
|
+
}): void;
|
|
9
19
|
}
|
|
10
20
|
//# sourceMappingURL=Levels.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Levels.d.ts","sourceRoot":"","sources":["../../../../src/services/Levels/Levels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E,qBAAa,MAAO,SAAQ,MAAO,YAAW,eAAe;IAC3D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"Levels.d.ts","sourceRoot":"","sources":["../../../../src/services/Levels/Levels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E,qBAAa,MAAO,SAAQ,MAAO,YAAW,eAAe;IAC3D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAK1F,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAKzF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAK1F,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAK3F,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAK/F"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { Logger } from "../Logger/Logger.js";
|
|
2
2
|
import { LogLevels } from "../../core/enum/LogLevels.js";
|
|
3
3
|
export class Levels extends Logger {
|
|
4
|
-
info(message, meta) {
|
|
5
|
-
const entry = this.getLogEntry(message, LogLevels.INFO, meta);
|
|
4
|
+
info(message, meta, options) {
|
|
5
|
+
const entry = this.getLogEntry(message, LogLevels.INFO, meta, options);
|
|
6
6
|
this.log(entry);
|
|
7
7
|
}
|
|
8
|
-
warn(message, meta) {
|
|
9
|
-
const entry = this.getLogEntry(message, LogLevels.WARN, meta);
|
|
8
|
+
warn(message, meta, options) {
|
|
9
|
+
const entry = this.getLogEntry(message, LogLevels.WARN, meta, options);
|
|
10
10
|
this.log(entry);
|
|
11
11
|
}
|
|
12
|
-
error(message, meta) {
|
|
13
|
-
const entry = this.getLogEntry(message, LogLevels.ERROR, meta);
|
|
12
|
+
error(message, meta, options) {
|
|
13
|
+
const entry = this.getLogEntry(message, LogLevels.ERROR, meta, options);
|
|
14
14
|
this.log(entry);
|
|
15
15
|
}
|
|
16
|
-
debug(message, meta) {
|
|
17
|
-
const entry = this.getLogEntry(message, LogLevels.DEBUG, meta);
|
|
16
|
+
debug(message, meta, options) {
|
|
17
|
+
const entry = this.getLogEntry(message, LogLevels.DEBUG, meta, options);
|
|
18
18
|
this.log(entry);
|
|
19
19
|
}
|
|
20
|
-
critical(message, meta) {
|
|
21
|
-
const entry = this.getLogEntry(message, LogLevels.CRITICAL, meta);
|
|
20
|
+
critical(message, meta, options) {
|
|
21
|
+
const entry = this.getLogEntry(message, LogLevels.CRITICAL, meta, options);
|
|
22
22
|
this.log(entry);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -7,9 +7,14 @@ export declare abstract class Logger {
|
|
|
7
7
|
private componentName;
|
|
8
8
|
private projectName;
|
|
9
9
|
private environment;
|
|
10
|
+
private readonly jsonizer;
|
|
11
|
+
private readonly serverTransporter;
|
|
12
|
+
private readonly consoleTransporter;
|
|
10
13
|
constructor(componentName: string, config: LogiscoutConfig);
|
|
11
14
|
protected log(entry: LogEntry): void;
|
|
12
15
|
getWinstonLogger(): WinstonLogger;
|
|
13
|
-
protected getLogEntry(message: string, logLevel: LogLevels, meta?: Record<string, unknown
|
|
16
|
+
protected getLogEntry(message: string, logLevel: LogLevels, meta?: Record<string, unknown>, options?: {
|
|
17
|
+
send?: boolean;
|
|
18
|
+
}): LogEntry;
|
|
14
19
|
}
|
|
15
20
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/services/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,IAAI,aAAa,EAAsB,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAW3D,8BAAsB,MAAM;IAC1B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;gBAE1C,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe;IA6B1D,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IA0CpC,gBAAgB,IAAI,aAAa;IAIjC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,QAAQ;CAgBZ"}
|
|
@@ -1,122 +1,75 @@
|
|
|
1
|
-
import winston
|
|
1
|
+
import winston from "winston";
|
|
2
2
|
import { LogLevels } from "../../core/enum/LogLevels.js";
|
|
3
3
|
import { RequestContext } from "../../core/context/RequestContext.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ConsoleTransporter } from "../transporter/ConsoleTranspoter.js";
|
|
5
|
+
import { LOG_LEVEL_SEVERITY } from "../../core/constants/Levels/LevelsSeverity.js";
|
|
6
|
+
import validateComponentName from "../../validator/ValidateComponentName.js";
|
|
7
|
+
import { throwError } from "../../errors/ThrowError.js";
|
|
8
|
+
import validateLogEntry from "../../validator/ValidateLogEntry.js";
|
|
9
|
+
import validateLogMessage from "../../validator/ValidateLogMessage.js";
|
|
10
|
+
import validateLogLevel from "../../validator/ValidateLogLevel.js";
|
|
11
|
+
import { Jsonizer } from "../processors/Jsonizer.js";
|
|
12
|
+
import { ServerTransporter } from "../transporter/ServerTransporter.js";
|
|
5
13
|
export class Logger {
|
|
6
14
|
winstonLogger;
|
|
7
15
|
componentName;
|
|
8
16
|
projectName;
|
|
9
17
|
environment;
|
|
18
|
+
jsonizer;
|
|
19
|
+
serverTransporter;
|
|
20
|
+
consoleTransporter;
|
|
10
21
|
constructor(componentName, config) {
|
|
11
|
-
|
|
12
|
-
if (!componentName || typeof componentName !== "string") {
|
|
13
|
-
throw new Error("Logger: Component name must be a non-empty string. " +
|
|
14
|
-
"Usage: createLogger('ComponentName')");
|
|
15
|
-
}
|
|
16
|
-
if (componentName.length > 100) {
|
|
17
|
-
throw new Error("Logger: Component name cannot exceed 100 characters. " +
|
|
18
|
-
`Received: '${componentName.substring(0, 20)}...'`);
|
|
19
|
-
}
|
|
22
|
+
validateComponentName(componentName);
|
|
20
23
|
this.componentName = componentName;
|
|
21
24
|
this.projectName = config.projectName;
|
|
22
25
|
this.environment = config.environment;
|
|
26
|
+
this.jsonizer = new Jsonizer({
|
|
27
|
+
projectName: this.projectName,
|
|
28
|
+
environment: this.environment,
|
|
29
|
+
componentName: this.componentName,
|
|
30
|
+
});
|
|
31
|
+
this.serverTransporter = new ServerTransporter();
|
|
32
|
+
this.consoleTransporter = new ConsoleTransporter();
|
|
23
33
|
try {
|
|
24
|
-
// Create structlog-style formatter instance
|
|
25
|
-
const consoleFormatter = new ConsoleFormatter();
|
|
26
34
|
this.winstonLogger = winston.createLogger({
|
|
27
|
-
level:
|
|
28
|
-
levels:
|
|
29
|
-
|
|
30
|
-
warn: 1,
|
|
31
|
-
info: 2,
|
|
32
|
-
debug: 3,
|
|
33
|
-
},
|
|
34
|
-
// File transport format (non-colorized)
|
|
35
|
-
format: format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, ...meta }) => {
|
|
36
|
-
const formatted = consoleFormatter.format({
|
|
37
|
-
level: level,
|
|
38
|
-
message: String(message),
|
|
39
|
-
timestamp: String(timestamp),
|
|
40
|
-
component: component,
|
|
41
|
-
...meta,
|
|
42
|
-
});
|
|
43
|
-
return `[${config.projectName}] ${formatted}`;
|
|
44
|
-
})),
|
|
45
|
-
transports: [
|
|
46
|
-
new transports.Console({
|
|
47
|
-
// Console transport with structlog-style formatting and colors
|
|
48
|
-
format: format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, ...meta }) => {
|
|
49
|
-
const formatted = consoleFormatter.format({
|
|
50
|
-
level: level,
|
|
51
|
-
message: String(message),
|
|
52
|
-
timestamp: String(timestamp),
|
|
53
|
-
component: component,
|
|
54
|
-
...meta,
|
|
55
|
-
});
|
|
56
|
-
return formatted;
|
|
57
|
-
})),
|
|
58
|
-
}),
|
|
59
|
-
],
|
|
35
|
+
level: LogLevels.DEBUG,
|
|
36
|
+
levels: LOG_LEVEL_SEVERITY,
|
|
37
|
+
transports: [this.consoleTransporter.transport()],
|
|
60
38
|
});
|
|
61
39
|
}
|
|
62
40
|
catch (error) {
|
|
63
|
-
|
|
41
|
+
throwError(`Logger: Failed to initialize Winston logger. ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
64
42
|
}
|
|
65
43
|
}
|
|
66
44
|
log(entry) {
|
|
67
45
|
try {
|
|
68
46
|
// Validate log entry
|
|
69
|
-
|
|
70
|
-
console.error("[Logiscout] Error: Log entry is undefined or null");
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (!entry.message || typeof entry.message !== "string") {
|
|
74
|
-
console.error("[Logiscout] Error: Log message must be a non-empty string. " +
|
|
75
|
-
`Usage: logiscout.${entry.level}('Your message', { meta })`);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (entry.message.length > 10000) {
|
|
79
|
-
console.error("[Logiscout] Error: Log message exceeds 10000 characters. " +
|
|
80
|
-
"Message truncated for logging.");
|
|
81
|
-
entry.message = entry.message.substring(0, 10000) + "... [truncated]";
|
|
82
|
-
}
|
|
47
|
+
validateLogEntry(entry);
|
|
83
48
|
const correlationId = RequestContext.getCorrelationId() ?? "no-correlation-id";
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
correlationId,
|
|
90
|
-
...entry.meta,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch (metaError) {
|
|
94
|
-
console.error("[Logiscout] Error: Failed to process metadata. Logging without metadata.", metaError instanceof Error ? metaError.message : "Unknown error");
|
|
95
|
-
logMeta = {
|
|
96
|
-
component: this.componentName,
|
|
97
|
-
correlationId,
|
|
98
|
-
_metaError: "Failed to process metadata",
|
|
99
|
-
};
|
|
100
|
-
}
|
|
49
|
+
let logMeta = {
|
|
50
|
+
component: this.componentName,
|
|
51
|
+
correlationId,
|
|
52
|
+
...(entry.meta ?? {}),
|
|
53
|
+
};
|
|
101
54
|
this.winstonLogger.log(entry.level, entry.message, logMeta);
|
|
55
|
+
this.jsonizer.appendLog(correlationId, {
|
|
56
|
+
timestamp: new Date().toISOString(),
|
|
57
|
+
level: entry.level,
|
|
58
|
+
message: entry.message,
|
|
59
|
+
meta: logMeta,
|
|
60
|
+
});
|
|
61
|
+
const logs = {
|
|
62
|
+
...entry,
|
|
63
|
+
projectName: this.projectName,
|
|
64
|
+
component: this.componentName,
|
|
65
|
+
correlationId,
|
|
66
|
+
};
|
|
102
67
|
if (entry.send && this.environment == "prod") {
|
|
103
68
|
// console.log("sending to he server")
|
|
104
|
-
|
|
105
|
-
// LogApi({
|
|
106
|
-
// logs: {
|
|
107
|
-
// ...entry,
|
|
108
|
-
// component: this.componentName,
|
|
109
|
-
// correlationId,
|
|
110
|
-
// },
|
|
111
|
-
// });
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// console.log("Showed to the user")
|
|
69
|
+
this.serverTransporter.transport(logs);
|
|
115
70
|
}
|
|
116
71
|
}
|
|
117
72
|
catch (error) {
|
|
118
|
-
// Silent failure - logger should never crash the application
|
|
119
|
-
// Log to console as last resort
|
|
120
73
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
121
74
|
console.error(`[Logiscout] Critical: Logger failed to write log: ${errorMessage}`);
|
|
122
75
|
}
|
|
@@ -124,23 +77,17 @@ export class Logger {
|
|
|
124
77
|
getWinstonLogger() {
|
|
125
78
|
return this.winstonLogger;
|
|
126
79
|
}
|
|
127
|
-
getLogEntry(message, logLevel, meta) {
|
|
80
|
+
getLogEntry(message, logLevel, meta, options) {
|
|
128
81
|
// Validate message
|
|
129
|
-
|
|
130
|
-
throw new Error(`Logger: Message must be a non-empty string. ` +
|
|
131
|
-
`Received: ${typeof message === "undefined" ? "undefined" : typeof message}`);
|
|
132
|
-
}
|
|
82
|
+
validateLogMessage(message);
|
|
133
83
|
// Validate log level
|
|
134
|
-
|
|
135
|
-
throw new Error(`Logger: Invalid log level '${logLevel}'. ` +
|
|
136
|
-
`Valid levels: ${Object.values(LogLevels).join(", ")}`);
|
|
137
|
-
}
|
|
84
|
+
validateLogLevel(logLevel);
|
|
138
85
|
const entry = {
|
|
139
86
|
message,
|
|
140
87
|
meta,
|
|
141
88
|
timestamp: new Date().toISOString(),
|
|
142
89
|
level: logLevel,
|
|
143
|
-
send: true
|
|
90
|
+
send: options?.send ?? true,
|
|
144
91
|
};
|
|
145
92
|
return entry;
|
|
146
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleFormatter.d.ts","sourceRoot":"","sources":["../../../../src/services/formatters/ConsoleFormatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConsoleFormatter.d.ts","sourceRoot":"","sources":["../../../../src/services/formatters/ConsoleFormatter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAIzD,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,IAAI,EAAE;QACX,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,GAAG,MAAM;IAoBV,OAAO,CAAC,UAAU;CAOnB"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const LEVEL_COLORS = {
|
|
3
|
-
[LogLevels.DEBUG]: "\x1b[90m", // gray
|
|
4
|
-
[LogLevels.INFO]: "\x1b[32m", // green
|
|
5
|
-
[LogLevels.WARN]: "\x1b[33m", // yellow
|
|
6
|
-
[LogLevels.ERROR]: "\x1b[31m", // red
|
|
7
|
-
[LogLevels.CRITICAL]: "\x1b[35m" // magenta
|
|
8
|
-
};
|
|
1
|
+
import { LEVEL_COLORS } from "../../core/constants/Levels/LevelsColors.js";
|
|
9
2
|
const RESET = "\x1b[0m";
|
|
10
3
|
export class ConsoleFormatter {
|
|
11
4
|
format(data) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CorrelationSession } from "../../core/interface/CorrelationSession.js";
|
|
2
|
+
import { JsonizerConfig } from "../../core/interface/JsonzierConfig.js";
|
|
3
|
+
import { LogEntry } from "../../core/types/LogEntry.js";
|
|
4
|
+
export declare class Jsonizer {
|
|
5
|
+
private readonly projectName;
|
|
6
|
+
private readonly environment;
|
|
7
|
+
private readonly componentName;
|
|
8
|
+
constructor(config: JsonizerConfig);
|
|
9
|
+
appendLog(correlationId: string, entry: LogEntry): CorrelationSession;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Jsonizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Jsonizer.d.ts","sourceRoot":"","sources":["../../../../src/services/processors/Jsonizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAKxD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,MAAM,EAAE,cAAc;IAM3B,SAAS,CACd,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,GACd,kBAAkB;CAkBtB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getOrCreateSession } from "../../core/store/CorrelationStore.js";
|
|
2
|
+
export class Jsonizer {
|
|
3
|
+
projectName;
|
|
4
|
+
environment;
|
|
5
|
+
componentName;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.projectName = config.projectName;
|
|
8
|
+
this.environment = config.environment;
|
|
9
|
+
this.componentName = config.componentName;
|
|
10
|
+
}
|
|
11
|
+
appendLog(correlationId, entry) {
|
|
12
|
+
const session = getOrCreateSession(correlationId, {
|
|
13
|
+
projectName: this.projectName,
|
|
14
|
+
environment: this.environment,
|
|
15
|
+
correlationId,
|
|
16
|
+
component: this.componentName,
|
|
17
|
+
});
|
|
18
|
+
session.logs.push({
|
|
19
|
+
timestamp: new Date().toISOString(),
|
|
20
|
+
level: entry.level,
|
|
21
|
+
message: entry.message,
|
|
22
|
+
meta: entry.meta ?? {},
|
|
23
|
+
component: this.componentName,
|
|
24
|
+
});
|
|
25
|
+
return session;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsoleTranspoter.d.ts","sourceRoot":"","sources":["../../../../src/services/transporter/ConsoleTranspoter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,SAAS,CAAC;AAGhD,qBAAa,kBAAkB;IAC7B,SAAS,IAAI,SAAS;CAKvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CorrelationSession, NonCorrelationSession } from "../../core/interface/CorrelationSession.js";
|
|
2
|
+
type AnySession = CorrelationSession | NonCorrelationSession;
|
|
3
|
+
export declare class ServerTransporter {
|
|
4
|
+
transport(session: AnySession): void;
|
|
5
|
+
private sendCorrelation;
|
|
6
|
+
private sendSingle;
|
|
7
|
+
private isFrontendSession;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=ServerTransporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerTransporter.d.ts","sourceRoot":"","sources":["../../../../src/services/transporter/ServerTransporter.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,4CAA4C,CAAC;AAEpD,KAAK,UAAU,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;AAE7D,qBAAa,iBAAiB;IAC5B,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IASpC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,iBAAiB;CAM1B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LogApi } from "../../api/LogApi.js";
|
|
2
|
+
import { LogPayloadType } from "../../core/enum/LogPayLoads.js";
|
|
3
|
+
export class ServerTransporter {
|
|
4
|
+
transport(session) {
|
|
5
|
+
if (this.isFrontendSession(session)) {
|
|
6
|
+
this.sendSingle(session);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
this.sendCorrelation(session);
|
|
10
|
+
}
|
|
11
|
+
sendCorrelation(session) {
|
|
12
|
+
LogApi({
|
|
13
|
+
type: LogPayloadType.SESSION,
|
|
14
|
+
data: session,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
sendSingle(session) {
|
|
18
|
+
LogApi({
|
|
19
|
+
type: LogPayloadType.SINGLE,
|
|
20
|
+
data: session,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
isFrontendSession(session) {
|
|
24
|
+
// Decide ONLY based on session shape/data
|
|
25
|
+
return session.correlationId === "no-correlation-id";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateCorrelationId.d.ts","sourceRoot":"","sources":["../../../src/utils/GenerateCorrelationId.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GACpB,MAAM,CAER"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateComponentName.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateComponentName.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,aAAa,EAAC,MAAM,QAajE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { throwError } from "../errors/ThrowError.js";
|
|
2
|
+
export default function validateComponentName(componentName) {
|
|
3
|
+
if (!componentName || typeof componentName !== "string") {
|
|
4
|
+
throwError("Logger: Component name must be a non-empty string. " +
|
|
5
|
+
"Usage: createLogger('ComponentName')");
|
|
6
|
+
}
|
|
7
|
+
if (componentName.length > 100) {
|
|
8
|
+
throwError("Logger: Component name cannot exceed 100 characters. " +
|
|
9
|
+
`Received: '${componentName.substring(0, 20)}...'`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogEntry.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAoB9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { throwError } from "../errors/ThrowError.js";
|
|
2
|
+
export default function validateLogEntry(entry) {
|
|
3
|
+
if (!entry) {
|
|
4
|
+
throwError("[Logiscout] Log entry is undefined or null");
|
|
5
|
+
}
|
|
6
|
+
if (!entry.message || typeof entry.message !== "string") {
|
|
7
|
+
throwError("[Logiscout] Log message must be a non-empty string. " +
|
|
8
|
+
`Usage: logiscout.${entry.level}('Your message', { meta })`);
|
|
9
|
+
}
|
|
10
|
+
if (entry.message.length > 10000) {
|
|
11
|
+
console.error("[Logiscout] Log message exceeds 10000 characters. Message truncated.");
|
|
12
|
+
entry.message =
|
|
13
|
+
entry.message.substring(0, 10000) + "... [truncated]";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogLevel.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogLevel.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAO5D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogLevels } from "../core/enum/LogLevels.js";
|
|
2
|
+
import { throwError } from "../errors/ThrowError.js";
|
|
3
|
+
export default function validateLogLevel(logLevel) {
|
|
4
|
+
if (!Object.values(LogLevels).includes(logLevel)) {
|
|
5
|
+
throwError(`Logger: Invalid log level '${logLevel}'. ` +
|
|
6
|
+
`Valid levels: ${Object.values(LogLevels).join(", ")}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogMessage.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogMessage.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAShE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { throwError } from "../errors/ThrowError.js";
|
|
2
|
+
export default function validateLogMessage(message) {
|
|
3
|
+
if (!message || typeof message !== "string") {
|
|
4
|
+
throwError(`Logger: Message must be a non-empty string. ` +
|
|
5
|
+
`Received: ${typeof message === "undefined" ? "undefined" : typeof message}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateRequestContext.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateRequestContext.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,MAAM,IAAI,EACd,aAAa,EAAE,MAAM,GAAC,SAAS,GAC9B,IAAI,CAqBN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { throwError } from "../errors/ThrowError.js";
|
|
2
|
+
export function validateRequestContext(fn, correlationId) {
|
|
3
|
+
if (typeof fn !== "function") {
|
|
4
|
+
throwError("RequestContext.run() requires a function as the first parameter. " +
|
|
5
|
+
"Usage: RequestContext.run(() => { ... }, correlationId?)");
|
|
6
|
+
}
|
|
7
|
+
// Validate correlationId if provided
|
|
8
|
+
if (correlationId !== undefined && typeof correlationId !== "string") {
|
|
9
|
+
throwError("RequestContext.run(): correlationId must be a string if provided. " +
|
|
10
|
+
`Received: ${typeof correlationId}`);
|
|
11
|
+
}
|
|
12
|
+
if (correlationId && correlationId.length > 100) {
|
|
13
|
+
throwError("RequestContext.run(): correlationId cannot exceed 100 characters.");
|
|
14
|
+
}
|
|
15
|
+
}
|