nextrans-logger 0.1.13 → 0.1.14
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/lib/index.cjs +6 -3
- package/lib/index.js +6 -3
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -7,6 +7,9 @@ require('dotenv').config();
|
|
|
7
7
|
const winston_1 = require("winston");
|
|
8
8
|
const winston_cloudwatch_1 = __importDefault(require("winston-cloudwatch"));
|
|
9
9
|
const winston_slack_webhook_transport_1 = __importDefault(require("winston-slack-webhook-transport"));
|
|
10
|
+
function replaceAnsi(data) {
|
|
11
|
+
return data.replace(/[\u001b\u009b][[()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
|
12
|
+
}
|
|
10
13
|
function formatMessage(log, env) {
|
|
11
14
|
var _a, _b, _c;
|
|
12
15
|
const message = [];
|
|
@@ -59,7 +62,7 @@ class Logging {
|
|
|
59
62
|
this.cloudwatchOption = cloudwatchOption;
|
|
60
63
|
}
|
|
61
64
|
lineFormat(log) {
|
|
62
|
-
return formatMessage(log, this.env).replace(/`/g, '')
|
|
65
|
+
return formatMessage(log, this.env).replace(/`/g, '');
|
|
63
66
|
}
|
|
64
67
|
formatPrint() {
|
|
65
68
|
return winston_1.format.combine(winston_1.format.colorize({ all: true, colors: { info: 'blue', error: 'red', warn: 'yellow' } }), winston_1.format.errors({ stack: true }), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.format.printf((log) => this.lineFormat(log)));
|
|
@@ -78,7 +81,7 @@ class Logging {
|
|
|
78
81
|
level,
|
|
79
82
|
webhookUrl: this.slackWebhook,
|
|
80
83
|
formatter: (log) => ({
|
|
81
|
-
text: `:sos: ${formatMessage(log, this.env)
|
|
84
|
+
text: `:sos: ${replaceAnsi(formatMessage(log, this.env))}`,
|
|
82
85
|
}),
|
|
83
86
|
});
|
|
84
87
|
transportsData.push(slack('error'));
|
|
@@ -104,7 +107,7 @@ class Logging {
|
|
|
104
107
|
region: (_c = this.cloudwatchOption) === null || _c === void 0 ? void 0 : _c.region,
|
|
105
108
|
credentials: (_d = this === null || this === void 0 ? void 0 : this.cloudwatchOption) === null || _d === void 0 ? void 0 : _d.credentials,
|
|
106
109
|
},
|
|
107
|
-
messageFormatter: (log) => this.lineFormat(log)
|
|
110
|
+
messageFormatter: (log) => replaceAnsi(this.lineFormat(log)),
|
|
108
111
|
});
|
|
109
112
|
};
|
|
110
113
|
log.add(cloudwatch());
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,9 @@ require('dotenv').config();
|
|
|
2
2
|
import { createLogger, format, transports } from 'winston';
|
|
3
3
|
import WinstonCloudwatch from 'winston-cloudwatch';
|
|
4
4
|
import SlackHook from 'winston-slack-webhook-transport';
|
|
5
|
+
function replaceAnsi(data) {
|
|
6
|
+
return data.replace(/[\u001b\u009b][[()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
|
7
|
+
}
|
|
5
8
|
function formatMessage(log, env) {
|
|
6
9
|
const message = [];
|
|
7
10
|
const newDate = new Date();
|
|
@@ -55,7 +58,7 @@ export default class Logging {
|
|
|
55
58
|
this.cloudwatchOption = cloudwatchOption;
|
|
56
59
|
}
|
|
57
60
|
lineFormat(log) {
|
|
58
|
-
return formatMessage(log, this.env).replace(/`/g, '')
|
|
61
|
+
return formatMessage(log, this.env).replace(/`/g, '');
|
|
59
62
|
}
|
|
60
63
|
formatPrint() {
|
|
61
64
|
return format.combine(format.colorize({ all: true, colors: { info: 'blue', error: 'red', warn: 'yellow' } }), format.errors({ stack: true }), format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.printf((log) => this.lineFormat(log)));
|
|
@@ -73,7 +76,7 @@ export default class Logging {
|
|
|
73
76
|
level,
|
|
74
77
|
webhookUrl: this.slackWebhook,
|
|
75
78
|
formatter: (log) => ({
|
|
76
|
-
text: `:sos: ${formatMessage(log, this.env)
|
|
79
|
+
text: `:sos: ${replaceAnsi(formatMessage(log, this.env))}`,
|
|
77
80
|
}),
|
|
78
81
|
});
|
|
79
82
|
transportsData.push(slack('error'));
|
|
@@ -97,7 +100,7 @@ export default class Logging {
|
|
|
97
100
|
region: this.cloudwatchOption?.region,
|
|
98
101
|
credentials: this?.cloudwatchOption?.credentials,
|
|
99
102
|
},
|
|
100
|
-
messageFormatter: (log) => this.lineFormat(log)
|
|
103
|
+
messageFormatter: (log) => replaceAnsi(this.lineFormat(log)),
|
|
101
104
|
});
|
|
102
105
|
log.add(cloudwatch());
|
|
103
106
|
}
|