Repository: pinojs/pino (js)

Issue:
msg property is not logged when first arg is undefined
In node.js (tested in 14 and 16), logs do not contain the `msg` property when the first parameter is `undefined`.

The following code
```
const logger = require("pino")();

logger.info("hello world");
logger.info({ a: 1 }, "hello world");
logger.info(null, "hello world");
logger.info(undefined, "hello world");

const child = logger.child({ a: "im a child" });
child.info({ a: 1 }, "hello daddy");
child.info(null, "hello daddy");
child.info(undefined, "hello daddy");
```

logs the following content (hostname has been changed 😉 ):

```
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","msg":"hello world"}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","a":1,"msg":"hello world"}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","msg":"hello world"}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"..."}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","a":"im a child","a":1,"msg":"hello daddy"}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","a":"im a child","msg":"hello daddy"}
{"level":30,"time":1663063554791,"pid":43360,"hostname":"...","a":"im a child"}
```

We can see the 4th log of both main logger and child logger does not have a `msg` property whereas it is ok when the first parameter is `null`.

However, it seems to be ok in the browser.
Tested here : https://codesandbox.io/s/js-playground-forked-qsnm99?file=/src/index.js

Pull request description:
fix(tools): log[level] compatible with when first argument is undefined (fix #1555)
fix #1555

**unit test added**

Patch:
diff --git a/lib/tools.js b/lib/tools.js
index 674198b..b44a961 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -53,7 +53,7 @@ function genLog (level, hook) {
       }
       this[writeSym](o, format(msg, formatParams, this[formatOptsSym]), level)
     } else {
-      this[writeSym](null, format(o, n, this[formatOptsSym]), level)
+      this[writeSym](null, format(o === undefined ? n.shift() : o, n, this[formatOptsSym]), level)
     }
   }
 }


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index ca4ca1e..e8310d6 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -109,6 +109,22 @@ function levelTest (name, level) {
     same(Object.keys(obj), ['hello'])
   })
 
+  test(`passing a undefined and a string at level ${name}`, async ({ equal, same }) => {
+    const stream = sink()
+    const instance = pino(stream)
+    instance.level = name
+    instance[name](undefined, 'a string')
+    const result = await once(stream, 'data')
+    equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
+    delete result.time
+    same(result, {
+      pid,
+      hostname,
+      level,
+      msg: 'a string'
+    })
+  })
+
   test(`overriding object key by string at level ${name}`, async ({ equal, same }) => {
     const stream = sink()
     const instance = pino(stream)