@trojs/logger 0.5.14 → 0.5.16
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 +1 -1
- package/src/loggers/console.js +15 -6
package/package.json
CHANGED
package/src/loggers/console.js
CHANGED
|
@@ -7,11 +7,16 @@ export default ({ winston, logger }) => {
|
|
|
7
7
|
winston.format.errors({ stack: logger?.debug ?? false }),
|
|
8
8
|
winston.format((info) => {
|
|
9
9
|
if (!info.message) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (info instanceof Error) {
|
|
11
|
+
info.message = info.message || info.toString()
|
|
12
|
+
} else {
|
|
13
|
+
const clone = { ...info }
|
|
14
|
+
delete clone.level
|
|
15
|
+
const keys = Object.keys(clone)
|
|
16
|
+
info.message = keys.length > 0 ? JSON.stringify(clone) : ''
|
|
17
|
+
}
|
|
13
18
|
} else if (info.message instanceof Error) {
|
|
14
|
-
info.message = info.message.toString()
|
|
19
|
+
info.message = info.message.message || info.message.toString()
|
|
15
20
|
} else if (typeof info.message !== 'string') {
|
|
16
21
|
info.message = JSON.stringify(info.message)
|
|
17
22
|
}
|
|
@@ -34,8 +39,10 @@ export default ({ winston, logger }) => {
|
|
|
34
39
|
const defaultFormatter = winston.format.combine(
|
|
35
40
|
winston.format.errors({ stack: logger?.debug ?? false }),
|
|
36
41
|
winston.format((info) => {
|
|
37
|
-
if (
|
|
38
|
-
info.message = info.toString()
|
|
42
|
+
if (info instanceof Error) {
|
|
43
|
+
info.message = info.message || info.toString()
|
|
44
|
+
} else if (!info.message) {
|
|
45
|
+
info.message = ''
|
|
39
46
|
}
|
|
40
47
|
return info
|
|
41
48
|
})(),
|
|
@@ -44,6 +51,8 @@ export default ({ winston, logger }) => {
|
|
|
44
51
|
|
|
45
52
|
return new winston.transports.Console({
|
|
46
53
|
level: logger?.level || defaultLevel,
|
|
54
|
+
handleExceptions: true,
|
|
55
|
+
handleRejections: true,
|
|
47
56
|
format:
|
|
48
57
|
logger?.format === 'json'
|
|
49
58
|
? jsonFormatter
|