diff --git a/package.json b/package.json index 588b9cb..3d9af89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@serverless-guru/logger", - "version": "1.0.5", + "version": "1.0.6", "description": "Common logger utility", "main": "./lib/cjs/index.js", "types": "./lib/cjs/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 4b9a508..35421af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,7 @@ class Logger { private serviceName: string; private correlationId: string; + private resetCorrelationId: boolean; private applicationName: string; private persistentContext: JSONObject; private console: Console; @@ -35,6 +36,8 @@ class Logger { constructor(serviceName: string, applicationName: string, correlationId: string | null = null) { this.serviceName = serviceName; this.correlationId = correlationId ? correlationId : randomUUID(); + console.log(correlationId, this.correlationId); + this.resetCorrelationId = correlationId ? false : true; this.applicationName = applicationName; this.persistentContext = {}; this.console = @@ -63,9 +66,7 @@ class Logger { const arrayToLowerCase = (array: StringArray): StringArray => { if (Array.isArray(array)) { - return array - .filter((el) => typeof el === "string") - .map((el) => el.toLowerCase()); + return array.filter((el) => typeof el === "string").map((el) => el.toLowerCase()); } return []; }; @@ -261,6 +262,7 @@ class Logger { setCorrelationId(correlationId: string): void { if (correlationId) { this.correlationId = correlationId; + this.resetCorrelationId = true; } } @@ -275,9 +277,9 @@ class Logger { clearLogContext(): void { this.persistentContext = {}; - this.correlationId = ""; - this.applicationName = ""; - this.serviceName = ""; + if (this.resetCorrelationId) { + this.correlationId = randomUUID(); + } } metric(activity: string, meta: MetricMeta): void {