nextrans-logger 0.1.12 → 0.1.13
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 +7 -4
- package/lib/index.js +7 -4
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -36,15 +36,16 @@ function formatMessage(log, env) {
|
|
|
36
36
|
}
|
|
37
37
|
if (typeof (log === null || log === void 0 ? void 0 : log.stack) !== 'undefined') {
|
|
38
38
|
message.push('\n');
|
|
39
|
-
message.push(log === null || log === void 0 ? void 0 : log.stack);
|
|
39
|
+
message.push('```' + (log === null || log === void 0 ? void 0 : log.stack) + '```');
|
|
40
40
|
}
|
|
41
41
|
else if (typeof (log === null || log === void 0 ? void 0 : log.options) !== 'undefined') {
|
|
42
42
|
message.push('\n');
|
|
43
43
|
message.push(log === null || log === void 0 ? void 0 : log.options);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
.map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' :
|
|
45
|
+
const output = message
|
|
46
|
+
.map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' : `${data}`))
|
|
47
47
|
.join(' ');
|
|
48
|
+
return output;
|
|
48
49
|
}
|
|
49
50
|
class Logging {
|
|
50
51
|
constructor({ enable = false, slackWebhook, cloudwatchOption, env = 'DEVELOPMENT' }) {
|
|
@@ -76,7 +77,9 @@ class Logging {
|
|
|
76
77
|
const slack = (level) => new winston_slack_webhook_transport_1.default({
|
|
77
78
|
level,
|
|
78
79
|
webhookUrl: this.slackWebhook,
|
|
79
|
-
formatter: (log) => ({
|
|
80
|
+
formatter: (log) => ({
|
|
81
|
+
text: `:sos: ${formatMessage(log, this.env).replace(/\[31m/g, '').replace(/\[39m/g, '')}`,
|
|
82
|
+
}),
|
|
80
83
|
});
|
|
81
84
|
transportsData.push(slack('error'));
|
|
82
85
|
}
|
package/lib/index.js
CHANGED
|
@@ -30,15 +30,16 @@ function formatMessage(log, env) {
|
|
|
30
30
|
}
|
|
31
31
|
if (typeof log?.stack !== 'undefined') {
|
|
32
32
|
message.push('\n');
|
|
33
|
-
message.push(log?.stack);
|
|
33
|
+
message.push('```' + log?.stack + '```');
|
|
34
34
|
}
|
|
35
35
|
else if (typeof log?.options !== 'undefined') {
|
|
36
36
|
message.push('\n');
|
|
37
37
|
message.push(log?.options);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
.map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' :
|
|
39
|
+
const output = message
|
|
40
|
+
.map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' : `${data}`))
|
|
41
41
|
.join(' ');
|
|
42
|
+
return output;
|
|
42
43
|
}
|
|
43
44
|
export default class Logging {
|
|
44
45
|
env = 'DEVELOPMENT';
|
|
@@ -71,7 +72,9 @@ export default class Logging {
|
|
|
71
72
|
const slack = (level) => new SlackHook({
|
|
72
73
|
level,
|
|
73
74
|
webhookUrl: this.slackWebhook,
|
|
74
|
-
formatter: (log) => ({
|
|
75
|
+
formatter: (log) => ({
|
|
76
|
+
text: `:sos: ${formatMessage(log, this.env).replace(/\[31m/g, '').replace(/\[39m/g, '')}`,
|
|
77
|
+
}),
|
|
75
78
|
});
|
|
76
79
|
transportsData.push(slack('error'));
|
|
77
80
|
}
|