Repository: pinojs/pino (js)

Issue:
Options are ignored when logging to a file
Some pino options are ignored when the destination is a file. Also, `useLevelLabels` seems to be able to change after a logger is already created.

Repro code:

```js
const pino = require('pino')

const opts = {
  base: null,
  timestamp: () => ',"time":"none"',
  useLevelLabels: true
}
const logger = pino(opts, './my.log')

logger.info('first')
pino(opts).info('second') // stdout
logger.info('third')
```

Contents of `my.log`:

```json
{"level":30,"time":1535948917084,"msg":"first","pid":34728,"hostname":"ubuntu","v":1}
{"level":"info","time":1535948917085,"msg":"third","pid":34728,"hostname":"ubuntu","v":1}
```

Terminal output:

```json
{"level":"info","time":"none","msg":"second","v":1}
```

Notice how the `base` and `timestamp` options have no effect on the logger that writes to `./my.log`.
Also notice how `useLevelLabels` is ignored at first, but then works after the second logger is created that writes to `stdout`.

Pino: v5.4.0
Node: v10.9.0
OS: Ubuntu 18.04, Windows 10

Pull request:
Do not override opts if the destination is a string
Fixes #512.

Patch:
diff --git a/lib/tools.js b/lib/tools.js
index 439c9f4..4a03e4a 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -242,12 +242,9 @@ function createArgsNormalizer (defaultOptions) {
     if (typeof opts === 'string') {
       stream = new SonicBoom(opts)
       opts = {}
-    }
-    if (typeof stream === 'string') {
+    } else if (typeof stream === 'string') {
       stream = new SonicBoom(stream)
-      opts = {}
-    }
-    if (opts instanceof SonicBoom || opts.writable || opts._writableState) {
+    } else if (opts instanceof SonicBoom || opts.writable || opts._writableState) {
       stream = opts
       opts = null
     }


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index bb1082c..b241140 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -448,7 +448,7 @@ test('auto pino.destination with a string as second argument', async ({ same })
     os.tmpdir(),
     '_' + Math.random().toString(36).substr(2, 9)
   )
-  const instance = pino({}, tmp)
+  const instance = pino(null, tmp)
   instance.info('hello')
   await sleep(250)
   const result = JSON.parse(readFileSync(tmp).toString())
@@ -462,6 +462,27 @@ test('auto pino.destination with a string as second argument', async ({ same })
   })
 })
 
+test('does not override opts with a string as second argument', async ({ same }) => {
+  const tmp = join(
+    os.tmpdir(),
+    '_' + Math.random().toString(36).substr(2, 9)
+  )
+  const instance = pino({
+    timestamp: () => ',"time":"none"'
+  }, tmp)
+  instance.info('hello')
+  await sleep(250)
+  const result = JSON.parse(readFileSync(tmp).toString())
+  same(result, {
+    pid: pid,
+    hostname: hostname,
+    level: 30,
+    time: 'none',
+    msg: 'hello',
+    v: 1
+  })
+})
+
 // https://github.com/pinojs/pino/issues/222
 test('children with same names render in correct order', async ({ is }) => {
   const stream = sink()