@trojs/logger 2.3.0 → 2.4.0
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/package.json
CHANGED
|
@@ -85,6 +85,26 @@ export class SentryTransport extends TransportStream {
|
|
|
85
85
|
|
|
86
86
|
const sentryLevel = this.levelsMap[winstonLevel]
|
|
87
87
|
|
|
88
|
+
// Normalize message to string
|
|
89
|
+
let normalizedMessage = message
|
|
90
|
+
if (!normalizedMessage || normalizedMessage === '') {
|
|
91
|
+
// Try to get message from stack or error
|
|
92
|
+
if (meta.stack) {
|
|
93
|
+
normalizedMessage = (meta.stack.split('\n')[0] || '').trim()
|
|
94
|
+
} else if (meta.error instanceof Error) {
|
|
95
|
+
normalizedMessage = meta.error.message || meta.error.toString()
|
|
96
|
+
} else {
|
|
97
|
+
normalizedMessage = 'Empty log message'
|
|
98
|
+
}
|
|
99
|
+
} else if (typeof normalizedMessage !== 'string') {
|
|
100
|
+
// Stringify non-string messages
|
|
101
|
+
try {
|
|
102
|
+
normalizedMessage = JSON.stringify(normalizedMessage)
|
|
103
|
+
} catch {
|
|
104
|
+
normalizedMessage = String(normalizedMessage)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
88
108
|
return Sentry.withScope((scope) => {
|
|
89
109
|
if (tags !== undefined && SentryTransport.isObject(tags)) {
|
|
90
110
|
scope.setTags(tags)
|
|
@@ -100,11 +120,11 @@ export class SentryTransport extends TransportStream {
|
|
|
100
120
|
if (SentryTransport.shouldLogException(sentryLevel)) {
|
|
101
121
|
const error
|
|
102
122
|
= Object.values(info).find((value) => value instanceof Error)
|
|
103
|
-
?? new ExtendedError(info)
|
|
123
|
+
?? new ExtendedError({ ...info, message: normalizedMessage })
|
|
104
124
|
Sentry.captureException(error, { tags, level: sentryLevel })
|
|
105
125
|
} else {
|
|
106
126
|
// Capturing Messages
|
|
107
|
-
Sentry.captureMessage(
|
|
127
|
+
Sentry.captureMessage(normalizedMessage, sentryLevel)
|
|
108
128
|
}
|
|
109
129
|
})
|
|
110
130
|
}
|