@gus-eip/loggers 3.5.6 → 3.5.8

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>;
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
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>;
18
18
  }
@@ -52,10 +52,12 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
52
52
  const putParams = {
53
53
  logGroupName: this.logGroupName,
54
54
  logStreamName: logStreamName,
55
- logEvents: [{
55
+ logEvents: [
56
+ {
56
57
  message: formattedLog.message,
57
- timestamp: timestampMillis
58
- }],
58
+ timestamp: timestampMillis,
59
+ },
60
+ ],
59
61
  };
60
62
  try {
61
63
  await this.cloudwatch.putLogEvents(putParams).promise();
@@ -79,114 +81,116 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
79
81
  }
80
82
  }
81
83
  async sendAlerttoTeams(errorMessage, errorStack, handler, input, logStreamName) {
82
- console.log("Error message", errorMessage);
84
+ console.log('Error message', errorMessage);
83
85
  const webhookUrl = this.teamWebhookUrl;
84
86
  const timestamp = new Date().toISOString();
85
- const inputFacts = Object.keys(input).map(key => ({
87
+ const inputFacts = Object.keys(input).map((key) => ({
86
88
  name: `${key}:`,
87
- 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]),
88
92
  }));
89
93
  const alertMessage = {
90
- "@type": "MessageCard",
91
- "@context": "http://schema.org/extensions",
92
- "summary": "Error Alert",
93
- "themeColor": "FF0000",
94
- "title": "🚨 Application Error Alert 🚨",
95
- "sections": [
94
+ '@type': 'MessageCard',
95
+ '@context': 'http://schema.org/extensions',
96
+ summary: 'Error Alert',
97
+ themeColor: 'FF0000',
98
+ title: '🚨 Application Error Alert 🚨',
99
+ sections: [
96
100
  {
97
- "facts": [
101
+ facts: [
98
102
  {
99
- "name": "errorMessage:",
100
- "value": `\`\`\`${errorMessage}\`\`\``
103
+ name: 'errorMessage:',
104
+ value: `\`\`\`${errorMessage}\`\`\``,
101
105
  },
102
106
  {
103
- "name": "errorStack:",
104
- "value": `\`\`\`${errorStack}\`\`\``
107
+ name: 'errorStack:',
108
+ value: `\`\`\`${errorStack}\`\`\``,
105
109
  },
106
110
  {
107
- "name": "component:",
108
- "value": handler
111
+ name: 'component:',
112
+ value: handler,
109
113
  },
110
114
  {
111
- "name": "timestamp:",
112
- "value": timestamp
115
+ name: 'timestamp:',
116
+ value: timestamp,
113
117
  },
114
118
  {
115
- "name": "",
116
- "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})`,
117
121
  },
118
122
  ],
119
- "markdown": true
120
- }
121
- ]
123
+ markdown: true,
124
+ },
125
+ ],
122
126
  };
123
127
  try {
124
128
  await axios_1.default.post(webhookUrl, alertMessage, {
125
129
  headers: {
126
- "Content-Type": "application/json",
130
+ 'Content-Type': 'application/json',
127
131
  },
128
132
  });
129
- console.log("Message sent successfully");
133
+ console.log('Message sent successfully');
130
134
  }
131
135
  catch (error) {
132
- console.error("Error sending message:", error);
136
+ console.error('Error sending message:', error);
133
137
  }
134
138
  }
135
- ;
136
139
  async sendNotificationtoTeams(title, summary, handler, logStreamName, isFormattingRequired = true) {
137
- console.log("Notification summary", summary);
140
+ console.log('Notification summary', summary);
138
141
  const webhookUrl = this.teamWebhookUrl;
139
142
  const timestamp = new Date().toISOString();
140
143
  const headers = Object.keys(summary[0]);
141
144
  const headerRow = `| ${headers.join(' | ')} |`;
142
145
  const separatorRow = `| ${headers.map(() => '---').join(' | ')} |`;
143
- 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');
144
149
  const formattedSummary = [headerRow, separatorRow, rows].join('\n');
145
150
  const summaryMsg = isFormattingRequired ? formattedSummary : summary;
146
151
  const alertMessage = {
147
- "@type": "MessageCard",
148
- "@context": "http://schema.org/extensions",
149
- "summary": "System Alert",
150
- "themeColor": "FF0000",
151
- "title": `🚨 ${title} 🚨`,
152
- "sections": [
152
+ '@type': 'MessageCard',
153
+ '@context': 'http://schema.org/extensions',
154
+ summary: 'System Alert',
155
+ themeColor: 'FF0000',
156
+ title: `🚨 ${title} 🚨`,
157
+ sections: [
153
158
  {
154
- "facts": [
159
+ facts: [
155
160
  {
156
- "name": "summary:",
157
- "value": summaryMsg
161
+ name: 'summary:',
162
+ value: summaryMsg,
158
163
  },
159
164
  {
160
- "name": "component:",
161
- "value": handler
165
+ name: 'component:',
166
+ value: handler,
162
167
  },
163
168
  {
164
- "name": "timestamp:",
165
- "value": timestamp
169
+ name: 'timestamp:',
170
+ value: timestamp,
166
171
  },
167
172
  {
168
- "name": "",
169
- "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})`,
170
175
  },
171
176
  ],
172
- "markdown": true
173
- }
174
- ]
177
+ markdown: true,
178
+ },
179
+ ],
175
180
  };
176
181
  try {
177
182
  await axios_1.default.post(webhookUrl, alertMessage, {
178
183
  headers: {
179
- "Content-Type": "application/json",
184
+ 'Content-Type': 'application/json',
180
185
  },
181
186
  });
182
- console.log("Message sent successfully");
187
+ console.log('Message sent successfully');
183
188
  }
184
189
  catch (error) {
185
- console.error("Error sending message:", error);
190
+ console.error('Error sending message:', error);
186
191
  }
187
192
  }
188
- ;
189
- 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) {
190
194
  const logObject = {
191
195
  correlationId,
192
196
  timestamp,
@@ -201,15 +205,17 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
201
205
  logMessage,
202
206
  brand,
203
207
  secondaryKey,
208
+ entityKeyField,
209
+ entityKey,
204
210
  destinationObjectType,
205
211
  destinationObjectId,
206
212
  sourceObjectType,
207
213
  sourceObjectId,
208
- destinationResponse
214
+ destinationResponse,
209
215
  };
210
216
  await this.logToCloudWatch('info', logObject, logStreamName);
211
217
  }
212
- 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) {
213
219
  const logObject = {
214
220
  correlationId,
215
221
  timestamp,
@@ -224,11 +230,13 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
224
230
  errorMessage,
225
231
  brand,
226
232
  secondaryKey,
233
+ entityKeyField,
234
+ entityKey,
227
235
  destinationObjectType,
228
236
  destinationObjectId,
229
237
  sourceObjectType,
230
238
  sourceObjectId,
231
- destinationResponse
239
+ destinationResponse,
232
240
  };
233
241
  await this.logToCloudWatch('error', logObject, logStreamName);
234
242
  if (this.isAlertNeeded) {
@@ -254,7 +262,7 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
254
262
  destinationObjectId,
255
263
  sourceObjectType,
256
264
  sourceObjectId,
257
- destinationResponse
265
+ destinationResponse,
258
266
  };
259
267
  await this.logToCloudWatch('info', logObject, logStreamName);
260
268
  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.6",
3
+ "version": "3.5.8",
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",