@trojs/logger 0.5.14 → 0.5.15

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/logger",
3
3
  "description": "Winston logger for TroJS",
4
- "version": "0.5.14",
4
+ "version": "0.5.15",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -7,11 +7,18 @@ export default ({ winston, logger }) => {
7
7
  winston.format.errors({ stack: logger?.debug ?? false }),
8
8
  winston.format((info) => {
9
9
  if (!info.message) {
10
- info.message = info instanceof Error
11
- ? info.toString()
12
- : JSON.stringify(info)
10
+ if (info instanceof Error) {
11
+ // Prefer the raw message; fall back to toString
12
+ info.message = info.message || info.toString()
13
+ } else {
14
+ // Avoid {"level":"error"} as a message if level is the only key
15
+ const clone = { ...info }
16
+ delete clone.level
17
+ const keys = Object.keys(clone)
18
+ info.message = keys.length > 0 ? JSON.stringify(clone) : ''
19
+ }
13
20
  } else if (info.message instanceof Error) {
14
- info.message = info.message.toString()
21
+ info.message = info.message.message || info.message.toString()
15
22
  } else if (typeof info.message !== 'string') {
16
23
  info.message = JSON.stringify(info.message)
17
24
  }