@gus-eip/loggers 3.3.7 → 3.3.9
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.
@@ -3,11 +3,14 @@ export declare class CloudWatchLoggerService implements ILogger {
|
|
3
3
|
private readonly cloudwatch;
|
4
4
|
private region;
|
5
5
|
private logGroupName;
|
6
|
-
|
6
|
+
private teamWebhoookUrl;
|
7
|
+
private isAlertNeeded;
|
8
|
+
constructor(region: string, logGroupName: string, teamWebhoookUrl: string, isAlertNeeded: boolean);
|
7
9
|
private version;
|
8
10
|
createLogStream(logStreamName: string): Promise<any>;
|
9
11
|
logToCloudWatch(type: string, logObject: any, logStreamName: string): Promise<void>;
|
10
12
|
logStreamExists(logStreamName: string): Promise<boolean>;
|
13
|
+
sendAlerttoTeams(errorMessage: any, handler: any, input: any): Promise<any>;
|
11
14
|
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>;
|
12
15
|
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>;
|
13
16
|
}
|
@@ -13,12 +13,15 @@ exports.CloudWatchLoggerService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
14
14
|
const aws_sdk_1 = require("aws-sdk");
|
15
15
|
const cloudwatch_event_formatter_1 = require("./cloudwatch.event.formatter");
|
16
|
+
const axios_1 = require("axios");
|
16
17
|
let CloudWatchLoggerService = class CloudWatchLoggerService {
|
17
|
-
constructor(region, logGroupName) {
|
18
|
+
constructor(region, logGroupName, teamWebhoookUrl, isAlertNeeded) {
|
18
19
|
this.version = 'v1';
|
19
20
|
this.cloudwatch = new aws_sdk_1.CloudWatchLogs({ region: region });
|
20
21
|
this.region = region;
|
21
22
|
this.logGroupName = logGroupName;
|
23
|
+
this.teamWebhoookUrl = teamWebhoookUrl;
|
24
|
+
this.isAlertNeeded = isAlertNeeded;
|
22
25
|
}
|
23
26
|
async createLogStream(logStreamName) {
|
24
27
|
const createParams = {
|
@@ -28,7 +31,6 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
28
31
|
await this.cloudwatch.createLogStream(createParams).promise();
|
29
32
|
}
|
30
33
|
async logToCloudWatch(type, logObject, logStreamName) {
|
31
|
-
const MAX_LOG_EVENT_SIZE = 262144;
|
32
34
|
if (!(await this.logStreamExists(logStreamName))) {
|
33
35
|
await this.createLogStream(logStreamName);
|
34
36
|
}
|
@@ -41,16 +43,12 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
41
43
|
level: type,
|
42
44
|
date: new Date(),
|
43
45
|
});
|
44
|
-
let logMessage = formattedLog.message;
|
45
46
|
const timestampMillis = formattedLog.timestamp.getTime();
|
46
|
-
while (Buffer.byteLength(logMessage, 'utf-8') > MAX_LOG_EVENT_SIZE) {
|
47
|
-
logMessage = logMessage.slice(0, logMessage.length - 1);
|
48
|
-
}
|
49
47
|
const putParams = {
|
50
48
|
logGroupName: this.logGroupName,
|
51
49
|
logStreamName: logStreamName,
|
52
50
|
logEvents: [{
|
53
|
-
message:
|
51
|
+
message: formattedLog.message,
|
54
52
|
timestamp: timestampMillis
|
55
53
|
}],
|
56
54
|
};
|
@@ -59,7 +57,6 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
59
57
|
}
|
60
58
|
catch (error) {
|
61
59
|
console.error('Error putting log events:', error);
|
62
|
-
throw error;
|
63
60
|
}
|
64
61
|
}
|
65
62
|
async logStreamExists(logStreamName) {
|
@@ -74,9 +71,57 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
74
71
|
}
|
75
72
|
catch (error) {
|
76
73
|
console.error('Error checking log stream:', error);
|
77
|
-
throw error;
|
78
74
|
}
|
79
75
|
}
|
76
|
+
async sendAlerttoTeams(errorMessage, handler, input) {
|
77
|
+
console.log("Error message", errorMessage);
|
78
|
+
const webhookUrl = this.teamWebhoookUrl;
|
79
|
+
const timestamp = new Date().toISOString();
|
80
|
+
const environment = process.env.NODE_ENV || "unknown";
|
81
|
+
const inputFacts = Object.keys(input).map(key => ({
|
82
|
+
name: `${key}:`,
|
83
|
+
value: typeof input[key] === 'object' ? JSON.stringify(input[key], null, 2) : String(input[key])
|
84
|
+
}));
|
85
|
+
const alertMessage = {
|
86
|
+
"@type": "MessageCard",
|
87
|
+
"@context": "http://schema.org/extensions",
|
88
|
+
"summary": "Error Alert",
|
89
|
+
"themeColor": "FF0000",
|
90
|
+
"title": "🚨 Application Error Alert 🚨",
|
91
|
+
"sections": [
|
92
|
+
{
|
93
|
+
"facts": [
|
94
|
+
{
|
95
|
+
"name": "errorMessage:",
|
96
|
+
"value": `\`\`\`${errorMessage}\`\`\``
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "component:",
|
100
|
+
"value": handler
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"name": "timestamp:",
|
104
|
+
"value": timestamp
|
105
|
+
},
|
106
|
+
...inputFacts,
|
107
|
+
],
|
108
|
+
"markdown": true
|
109
|
+
}
|
110
|
+
]
|
111
|
+
};
|
112
|
+
try {
|
113
|
+
await axios_1.default.post(webhookUrl, alertMessage, {
|
114
|
+
headers: {
|
115
|
+
"Content-Type": "application/json",
|
116
|
+
},
|
117
|
+
});
|
118
|
+
console.log("Message sent successfully");
|
119
|
+
}
|
120
|
+
catch (error) {
|
121
|
+
console.error("Error sending message:", error);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
;
|
80
125
|
async log(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
|
81
126
|
const logObject = {
|
82
127
|
correlationId,
|
@@ -122,10 +167,13 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
122
167
|
destinationResponse
|
123
168
|
};
|
124
169
|
await this.logToCloudWatch('error', logObject, logStreamName);
|
170
|
+
if (this.isAlertNeeded) {
|
171
|
+
await this.sendAlerttoTeams(errorMessage, component, logObject);
|
172
|
+
}
|
125
173
|
}
|
126
174
|
};
|
127
|
-
CloudWatchLoggerService =
|
175
|
+
exports.CloudWatchLoggerService = CloudWatchLoggerService;
|
176
|
+
exports.CloudWatchLoggerService = CloudWatchLoggerService = __decorate([
|
128
177
|
(0, common_1.Injectable)(),
|
129
|
-
__metadata("design:paramtypes", [String, String])
|
178
|
+
__metadata("design:paramtypes", [String, String, String, Boolean])
|
130
179
|
], CloudWatchLoggerService);
|
131
|
-
exports.CloudWatchLoggerService = CloudWatchLoggerService;
|
package/dist/enum.js
CHANGED
package/dist/module.js
CHANGED
@@ -19,7 +19,7 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
19
19
|
};
|
20
20
|
const cloudwatchProviders = {
|
21
21
|
provide: params.options,
|
22
|
-
useFactory: () => new cloudwatch_logger_1.CloudWatchLoggerService(params.region, params.logGroupName),
|
22
|
+
useFactory: () => new cloudwatch_logger_1.CloudWatchLoggerService(params.region, params.logGroupName, params.teamWebhoookUrl, params.isAlertNeeded),
|
23
23
|
};
|
24
24
|
return {
|
25
25
|
module: LoggerModule_1,
|
@@ -28,7 +28,7 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
};
|
31
|
-
LoggerModule =
|
31
|
+
exports.LoggerModule = LoggerModule;
|
32
|
+
exports.LoggerModule = LoggerModule = LoggerModule_1 = __decorate([
|
32
33
|
(0, common_1.Module)({})
|
33
34
|
], LoggerModule);
|
34
|
-
exports.LoggerModule = LoggerModule;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gus-eip/loggers",
|
3
|
-
"version": "3.3.
|
3
|
+
"version": "3.3.9",
|
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",
|
@@ -40,6 +40,7 @@
|
|
40
40
|
"@nestjs/testing": "10.0.2",
|
41
41
|
"@types/express": "4.17.17",
|
42
42
|
"@types/jest": "29.5.2",
|
43
|
+
"@types/lodash": "^4.17.7",
|
43
44
|
"@types/node": "20.3.1",
|
44
45
|
"@types/supertest": "2.0.12",
|
45
46
|
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
@@ -57,7 +58,7 @@
|
|
57
58
|
"tsc-watch": "6.0.4",
|
58
59
|
"tsconfig-paths": "4.2.0",
|
59
60
|
"tslint": "5.20.1",
|
60
|
-
"typescript": "5.
|
61
|
+
"typescript": "^5.5.4"
|
61
62
|
},
|
62
63
|
"jest": {
|
63
64
|
"moduleFileExtensions": [
|