Repository: pinojs/pino-pretty (javascript)

Issue:
Pino Pretty does not output numbers but only strings.
I have a very simple log file with as below `app.log`
```
{"level":30,"time":"2023-06-19T04:01:56.478Z","pid":2484,"hostname":"YMLTITD2227","msg":77}
{"level":30,"time":"2023-06-19T04:01:56.478Z","pid":2484,"hostname":"YMLTITD2227","msg":"42"}
```

Notice that first message is number 77, while the other is string 42. If I do `cat app.log | npx pino-pretty`, I get the below output
```
[12:01:56.478] INFO (2484):
[12:01:56.478] INFO (2484): 42
```

It does NOT display the numbers, but only the strings. I was hoping that pino-pretty should be able to interpret numbers as strings.




Discussion:
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Patch:
diff --git a/index.js b/index.js
--- a/index.js
+++ b/index.js
@@ -162,7 +162,7 @@ function prettyFactory (options) {
       line += ':'
     }
 
-    if (prettifiedMessage) {
+    if (prettifiedMessage !== undefined) {
       if (line.length > 0) {
         line = `${line} ${prettifiedMessage}`
       } else {
@@ -186,7 +186,7 @@ function prettyFactory (options) {
       if (singleLine) line += EOL
       line += prettifiedErrorLog
     } else if (!hideObject) {
-      const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number')
+      const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number' || typeof log[key] === 'boolean')
       const prettifiedObject = prettifyObject({
         input: log,
         skipKeys,
diff --git a/lib/utils.js b/lib/utils.js
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -280,7 +280,7 @@ function prettifyMessage ({ log, messageFormat, messageKey = MESSAGE_KEY, colori
     return colorizer.message(msg)
   }
   if (messageKey in log === false) return undefined
-  if (typeof log[messageKey] !== 'string') return undefined
+  if (typeof log[messageKey] !== 'string' && typeof log[messageKey] !== 'number' && typeof log[messageKey] !== 'boolean') return undefined
   return colorizer.message(log[messageKey])
 }
 


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -118,6 +118,70 @@ test('basic prettifier tests', (t) => {
     log.info('foo')
   })
 
+  t.test('can print message key value when its a string', (t) => {
+    t.plan(1)
+    const pretty = prettyFactory()
+    const log = pino({}, new Writable({
+      write (chunk, enc, cb) {
+        const formatted = pretty(chunk.toString())
+        t.equal(
+          formatted,
+          `[${formattedEpoch}] INFO (${pid}): baz\n`
+        )
+        cb()
+      }
+    }))
+    log.info('baz')
+  })
+
+  t.test('can print message key value when its a number', (t) => {
+    t.plan(1)
+    const pretty = prettyFactory()
+    const log = pino({}, new Writable({
+      write (chunk, enc, cb) {
+        const formatted = pretty(chunk.toString())
+        t.equal(
+          formatted,
+          `[${formattedEpoch}] INFO (${pid}): 42\n`
+        )
+        cb()
+      }
+    }))
+    log.info(42)
+  })
+
+  t.test('can print message key value when its a Number(0)', (t) => {
+    t.plan(1)
+    const pretty = prettyFactory()
+    const log = pino({}, new Writable({
+      write (chunk, enc, cb) {
+        const formatted = pretty(chunk.toString())
+        t.equal(
+          formatted,
+          `[${formattedEpoch}] INFO (${pid}): 0\n`
+        )
+        cb()
+      }
+    }))
+    log.info(0)
+  })
+
+  t.test('can print message key value when its a boolean', (t) => {
+    t.plan(1)
+    const pretty = prettyFactory()
+    const log = pino({}, new Writable({
+      write (chunk, enc, cb) {
+        const formatted = pretty(chunk.toString())
+        t.equal(
+          formatted,
+          `[${formattedEpoch}] INFO (${pid}): true\n`
+        )
+        cb()
+      }
+    }))
+    log.info(true)
+  })
+
   t.test('can use different message keys', (t) => {
     t.plan(1)
     const pretty = prettyFactory({ messageKey: 'bar' })