Repository: pinojs/hapi-pino (js)

Issue:
prettyPrint does not work well with multiple servers
I instantiate 3 different servers and register `hapi-pino` into all 3 with `prettyPrint=true`, but only the first server to register will have pretty logs.

Pull request:
clone the options object to prevent errors due to internal mutations, fixes #44
  Fixed #44 

Patch:
diff --git a/index.js b/index.js
index 7245753..1168942 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
 'use strict'
 
+const Hoek = require('hoek')
 const pino = require('pino')
 const nullLogger = require('abstract-logging')
 
@@ -13,6 +14,9 @@ const levelTags = {
 }
 
 async function register (server, options) {
+  // clone all user options to account for internal mutations, except for existing stream and pino instances
+  options = Hoek.merge({ stream: options.stream, instance: options.instance }, Hoek.clone(options))
+
   options.serializers = options.serializers || {}
   options.serializers.req = wrapReqSerializer(options.serializers.req || asReqValue)
   options.serializers.res = wrapResSerializer(options.serializers.res || asResValue)
diff --git a/package.json b/package.json
index 3a114b7..5acd817 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
   },
   "dependencies": {
     "abstract-logging": "^1.0.0",
+    "hoek": "^5.0.2",
     "pino": "^4.10.2"
   },
   "repository": {


Test patch:
diff --git a/test.js b/test.js
index 0f32fff..fdc2a53 100644
--- a/test.js
+++ b/test.js
@@ -2,6 +2,7 @@
 
 const Code = require('code')
 const Lab = require('lab')
+const Hoek = require('hoek')
 const split = require('split2')
 const writeStream = require('flush-write-stream')
 const promisify = require('util').promisify
@@ -83,7 +84,7 @@ function onHelloWorld (data) {
 }
 
 function ltest (func) {
-  ;['trace', 'debug', 'info', 'warn', 'error'].forEach((level) => {
+  ['trace', 'debug', 'info', 'warn', 'error'].forEach((level) => {
     test(`at ${level}`, async () => {
       await func(level)
     })
@@ -293,6 +294,28 @@ experiment('logs each request', () => {
     await server.inject('/')
     await finish
   })
+
+  test('does not mutate options object', async () => {
+    const options = {
+      prettyPrint: true
+    }
+
+    let plugin
+    let optionsClone
+
+    async function register (server) {
+      plugin = {
+        plugin: Pino,
+        options
+      }
+
+      optionsClone = Hoek.clone(options)
+      await server.register(plugin)
+    }
+
+    await register(getServer())
+    expect(options).to.equal(optionsClone)
+  })
 })
 
 experiment('logs through server.log', () => {