@gus-eip/loggers 3.5.5 → 3.5.7

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.
@@ -12,7 +12,7 @@ export declare class CloudWatchLoggerService implements ILogger {
12
12
  logStreamExists(logStreamName: string): Promise<boolean>;
13
13
  sendAlerttoTeams(errorMessage: any, errorStack: any, handler: any, input: any, logStreamName: any): Promise<any>;
14
14
  sendNotificationtoTeams(title: any, summary: any, handler: any, logStreamName: any, isFormattingRequired?: boolean): Promise<any>;
15
- log(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
16
- error(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, errorMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
17
- logAlert(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, isAlertFormattingRequired?: boolean, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
15
+ log(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, entityKeyField: string, entityKey: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
16
+ error(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, errorMessage: any, brand: any, secondaryKey: string, logStreamName: string, entityKeyField: string, entityKey: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
17
+ logAlert(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, entityKeyField: string, entityKey: string, isAlertFormattingRequired?: boolean, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
18
18
  }
@@ -31,28 +31,35 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
31
31
  await this.cloudwatch.createLogStream(createParams).promise();
32
32
  }
33
33
  async logToCloudWatch(type, logObject, logStreamName) {
34
- try {
35
- if (!(await this.logStreamExists(logStreamName))) {
34
+ if (!(await this.logStreamExists(logStreamName))) {
35
+ try {
36
36
  await this.createLogStream(logStreamName);
37
37
  }
38
- const formatter = new cloudwatch_event_formatter_1.CloudWatchEventFormatter();
39
- logObject.version = this.version;
40
- logObject.timestamp = new Date().toISOString();
41
- const formattedLog = formatter.formatLogItem({
42
- meta: logObject,
43
- ...logObject,
44
- level: type,
45
- date: new Date(),
46
- });
47
- const timestampMillis = formattedLog.timestamp.getTime();
48
- const putParams = {
49
- logGroupName: this.logGroupName,
50
- logStreamName: logStreamName,
51
- logEvents: [{
52
- message: formattedLog.message,
53
- timestamp: timestampMillis
54
- }],
55
- };
38
+ catch (error) {
39
+ console.error('Error creating log stream:', error);
40
+ }
41
+ }
42
+ const formatter = new cloudwatch_event_formatter_1.CloudWatchEventFormatter();
43
+ logObject.version = this.version;
44
+ logObject.timestamp = new Date().toISOString();
45
+ const formattedLog = formatter.formatLogItem({
46
+ meta: logObject,
47
+ ...logObject,
48
+ level: type,
49
+ date: new Date(),
50
+ });
51
+ const timestampMillis = formattedLog.timestamp.getTime();
52
+ const putParams = {
53
+ logGroupName: this.logGroupName,
54
+ logStreamName: logStreamName,
55
+ logEvents: [
56
+ {
57
+ message: formattedLog.message,
58
+ timestamp: timestampMillis,
59
+ },
60
+ ],
61
+ };
62
+ try {
56
63
  await this.cloudwatch.putLogEvents(putParams).promise();
57
64
  }
58
65
  catch (error) {
@@ -74,114 +81,116 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
74
81
  }
75
82
  }
76
83
  async sendAlerttoTeams(errorMessage, errorStack, handler, input, logStreamName) {
77
- console.log("Error message", errorMessage);
84
+ console.log('Error message', errorMessage);
78
85
  const webhookUrl = this.teamWebhookUrl;
79
86
  const timestamp = new Date().toISOString();
80
- const inputFacts = Object.keys(input).map(key => ({
87
+ const inputFacts = Object.keys(input).map((key) => ({
81
88
  name: `${key}:`,
82
- value: typeof input[key] === 'object' ? JSON.stringify(input[key], null, 2) : String(input[key])
89
+ value: typeof input[key] === 'object'
90
+ ? JSON.stringify(input[key], null, 2)
91
+ : String(input[key]),
83
92
  }));
84
93
  const alertMessage = {
85
- "@type": "MessageCard",
86
- "@context": "http://schema.org/extensions",
87
- "summary": "Error Alert",
88
- "themeColor": "FF0000",
89
- "title": "🚨 Application Error Alert 🚨",
90
- "sections": [
94
+ '@type': 'MessageCard',
95
+ '@context': 'http://schema.org/extensions',
96
+ summary: 'Error Alert',
97
+ themeColor: 'FF0000',
98
+ title: '🚨 Application Error Alert 🚨',
99
+ sections: [
91
100
  {
92
- "facts": [
101
+ facts: [
93
102
  {
94
- "name": "errorMessage:",
95
- "value": `\`\`\`${errorMessage}\`\`\``
103
+ name: 'errorMessage:',
104
+ value: `\`\`\`${errorMessage}\`\`\``,
96
105
  },
97
106
  {
98
- "name": "errorStack:",
99
- "value": `\`\`\`${errorStack}\`\`\``
107
+ name: 'errorStack:',
108
+ value: `\`\`\`${errorStack}\`\`\``,
100
109
  },
101
110
  {
102
- "name": "component:",
103
- "value": handler
111
+ name: 'component:',
112
+ value: handler,
104
113
  },
105
114
  {
106
- "name": "timestamp:",
107
- "value": timestamp
115
+ name: 'timestamp:',
116
+ value: timestamp,
108
117
  },
109
118
  {
110
- "name": "",
111
- "value": `[Click here for more details](https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName})`
119
+ name: '',
120
+ value: `[Click here for more details](https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName})`,
112
121
  },
113
122
  ],
114
- "markdown": true
115
- }
116
- ]
123
+ markdown: true,
124
+ },
125
+ ],
117
126
  };
118
127
  try {
119
128
  await axios_1.default.post(webhookUrl, alertMessage, {
120
129
  headers: {
121
- "Content-Type": "application/json",
130
+ 'Content-Type': 'application/json',
122
131
  },
123
132
  });
124
- console.log("Message sent successfully");
133
+ console.log('Message sent successfully');
125
134
  }
126
135
  catch (error) {
127
- console.error("Error sending message:", error);
136
+ console.error('Error sending message:', error);
128
137
  }
129
138
  }
130
- ;
131
139
  async sendNotificationtoTeams(title, summary, handler, logStreamName, isFormattingRequired = true) {
132
- console.log("Notification summary", summary);
140
+ console.log('Notification summary', summary);
133
141
  const webhookUrl = this.teamWebhookUrl;
134
142
  const timestamp = new Date().toISOString();
135
143
  const headers = Object.keys(summary[0]);
136
144
  const headerRow = `| ${headers.join(' | ')} |`;
137
145
  const separatorRow = `| ${headers.map(() => '---').join(' | ')} |`;
138
- const rows = summary.map(item => `| ${headers.map(header => item[header] || '').join(' | ')} |`).join('\n');
146
+ const rows = summary
147
+ .map((item) => `| ${headers.map((header) => item[header] || '').join(' | ')} |`)
148
+ .join('\n');
139
149
  const formattedSummary = [headerRow, separatorRow, rows].join('\n');
140
150
  const summaryMsg = isFormattingRequired ? formattedSummary : summary;
141
151
  const alertMessage = {
142
- "@type": "MessageCard",
143
- "@context": "http://schema.org/extensions",
144
- "summary": "System Alert",
145
- "themeColor": "FF0000",
146
- "title": `🚨 ${title} 🚨`,
147
- "sections": [
152
+ '@type': 'MessageCard',
153
+ '@context': 'http://schema.org/extensions',
154
+ summary: 'System Alert',
155
+ themeColor: 'FF0000',
156
+ title: `🚨 ${title} 🚨`,
157
+ sections: [
148
158
  {
149
- "facts": [
159
+ facts: [
150
160
  {
151
- "name": "summary:",
152
- "value": summaryMsg
161
+ name: 'summary:',
162
+ value: summaryMsg,
153
163
  },
154
164
  {
155
- "name": "component:",
156
- "value": handler
165
+ name: 'component:',
166
+ value: handler,
157
167
  },
158
168
  {
159
- "name": "timestamp:",
160
- "value": timestamp
169
+ name: 'timestamp:',
170
+ value: timestamp,
161
171
  },
162
172
  {
163
- "name": "",
164
- "value": `[Click here for more details](https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName})`
173
+ name: '',
174
+ value: `[Click here for more details](https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName})`,
165
175
  },
166
176
  ],
167
- "markdown": true
168
- }
169
- ]
177
+ markdown: true,
178
+ },
179
+ ],
170
180
  };
171
181
  try {
172
182
  await axios_1.default.post(webhookUrl, alertMessage, {
173
183
  headers: {
174
- "Content-Type": "application/json",
184
+ 'Content-Type': 'application/json',
175
185
  },
176
186
  });
177
- console.log("Message sent successfully");
187
+ console.log('Message sent successfully');
178
188
  }
179
189
  catch (error) {
180
- console.error("Error sending message:", error);
190
+ console.error('Error sending message:', error);
181
191
  }
182
192
  }
183
- ;
184
- async log(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
193
+ async log(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, entityKeyField, entityKey, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
185
194
  const logObject = {
186
195
  correlationId,
187
196
  timestamp,
@@ -196,15 +205,17 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
196
205
  logMessage,
197
206
  brand,
198
207
  secondaryKey,
208
+ entityKeyField,
209
+ entityKey,
199
210
  destinationObjectType,
200
211
  destinationObjectId,
201
212
  sourceObjectType,
202
213
  sourceObjectId,
203
- destinationResponse
214
+ destinationResponse,
204
215
  };
205
216
  await this.logToCloudWatch('info', logObject, logStreamName);
206
217
  }
207
- async error(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, errorMessage, brand, secondaryKey, logStreamName, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
218
+ async error(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, errorMessage, brand, secondaryKey, logStreamName, entityKeyField, entityKey, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
208
219
  const logObject = {
209
220
  correlationId,
210
221
  timestamp,
@@ -219,18 +230,20 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
219
230
  errorMessage,
220
231
  brand,
221
232
  secondaryKey,
233
+ entityKeyField,
234
+ entityKey,
222
235
  destinationObjectType,
223
236
  destinationObjectId,
224
237
  sourceObjectType,
225
238
  sourceObjectId,
226
- destinationResponse
239
+ destinationResponse,
227
240
  };
228
241
  await this.logToCloudWatch('error', logObject, logStreamName);
229
242
  if (this.isAlertNeeded) {
230
243
  await this.sendAlerttoTeams(errorMessage.message ? errorMessage.message : errorMessage, errorMessage.stack ? errorMessage.stack : errorMessage, component, logObject, encodeURIComponent(logStreamName));
231
244
  }
232
245
  }
233
- async logAlert(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, isAlertFormattingRequired, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
246
+ async logAlert(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, entityKeyField, entityKey, isAlertFormattingRequired, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
234
247
  const logObject = {
235
248
  correlationId,
236
249
  timestamp,
@@ -245,11 +258,13 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
245
258
  logMessage,
246
259
  brand,
247
260
  secondaryKey,
261
+ entityKeyField,
262
+ entityKey,
248
263
  destinationObjectType,
249
264
  destinationObjectId,
250
265
  sourceObjectType,
251
266
  sourceObjectId,
252
- destinationResponse
267
+ destinationResponse,
253
268
  };
254
269
  await this.logToCloudWatch('info', logObject, logStreamName);
255
270
  if (this.isAlertNeeded) {
@@ -1,4 +1,4 @@
1
1
  export interface ILogger {
2
- log(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
3
- error(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, errorMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
2
+ log(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, entityKeyField: string, entityKey: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
3
+ error(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, errorMessage: any, brand: any, secondaryKey: string, logStreamName: string, entityKeyField: string, entityKey: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gus-eip/loggers",
3
- "version": "3.5.5",
3
+ "version": "3.5.7",
4
4
  "description": "@gus-eip/loggers is a package designed to provide logging functionality for your Node.js applications.",
5
5
  "author": "gus",
6
6
  "readmeFilename": "README.md",