@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.
- package/dist/cloudwatch.logger.d.ts +2 -2
- package/dist/cloudwatch.logger.js +67 -59
- package/dist/interface.d.ts +2 -2
- package/package.json +1 -1
@@ -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(
|
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'
|
89
|
+
value: typeof input[key] === 'object'
|
90
|
+
? JSON.stringify(input[key], null, 2)
|
91
|
+
: String(input[key]),
|
88
92
|
}));
|
89
93
|
const alertMessage = {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
101
|
+
facts: [
|
98
102
|
{
|
99
|
-
|
100
|
-
|
103
|
+
name: 'errorMessage:',
|
104
|
+
value: `\`\`\`${errorMessage}\`\`\``,
|
101
105
|
},
|
102
106
|
{
|
103
|
-
|
104
|
-
|
107
|
+
name: 'errorStack:',
|
108
|
+
value: `\`\`\`${errorStack}\`\`\``,
|
105
109
|
},
|
106
110
|
{
|
107
|
-
|
108
|
-
|
111
|
+
name: 'component:',
|
112
|
+
value: handler,
|
109
113
|
},
|
110
114
|
{
|
111
|
-
|
112
|
-
|
115
|
+
name: 'timestamp:',
|
116
|
+
value: timestamp,
|
113
117
|
},
|
114
118
|
{
|
115
|
-
|
116
|
-
|
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
|
-
|
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
|
-
|
130
|
+
'Content-Type': 'application/json',
|
127
131
|
},
|
128
132
|
});
|
129
|
-
console.log(
|
133
|
+
console.log('Message sent successfully');
|
130
134
|
}
|
131
135
|
catch (error) {
|
132
|
-
console.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(
|
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
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
152
|
+
'@type': 'MessageCard',
|
153
|
+
'@context': 'http://schema.org/extensions',
|
154
|
+
summary: 'System Alert',
|
155
|
+
themeColor: 'FF0000',
|
156
|
+
title: `🚨 ${title} 🚨`,
|
157
|
+
sections: [
|
153
158
|
{
|
154
|
-
|
159
|
+
facts: [
|
155
160
|
{
|
156
|
-
|
157
|
-
|
161
|
+
name: 'summary:',
|
162
|
+
value: summaryMsg,
|
158
163
|
},
|
159
164
|
{
|
160
|
-
|
161
|
-
|
165
|
+
name: 'component:',
|
166
|
+
value: handler,
|
162
167
|
},
|
163
168
|
{
|
164
|
-
|
165
|
-
|
169
|
+
name: 'timestamp:',
|
170
|
+
value: timestamp,
|
166
171
|
},
|
167
172
|
{
|
168
|
-
|
169
|
-
|
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
|
-
|
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
|
-
|
184
|
+
'Content-Type': 'application/json',
|
180
185
|
},
|
181
186
|
});
|
182
|
-
console.log(
|
187
|
+
console.log('Message sent successfully');
|
183
188
|
}
|
184
189
|
catch (error) {
|
185
|
-
console.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) {
|
package/dist/interface.d.ts
CHANGED
@@ -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