Repository: pinojs/hapi-pino (js)

Issue:
 Cannot read property 'info' of undefined
I have been getting this error whenever I refresh my Apollo graphql playground and based on the error trace `request.logger` inside `tryAddEvent` function (request completes ) is undefined
```log
TypeError: Cannot read property 'info' of undefined
    at Object.listener (/home/akumzy/momo/planner-server/node_modules/hapi-pino/index.js:120:25)
    at module.exports.internals.Podium.internals.Podium.emit (/home/akumzy/momo/planner-server/node_modules/@hapi/podium/lib/index.js:224:107)
    at Request._finalize (/home/akumzy/momo/planner-server/node_modules/@hapi/hapi/lib/request.js:447:27)
    at Request._reply (/home/akumzy/momo/planner-server/node_modules/@hapi/hapi/lib/request.js:391:14)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

Pull request:
fix: use scoped logger if request.logger is not available
Fixes #84 

Patch:
diff --git a/.travis.yml b/.travis.yml
index 7d86635..3433997 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,9 +3,17 @@ sudo: false
 node_js:
   - "8"
   - "10"
+  - "12"
 env:
   - HAPI=hapi@17
-  - HAPI=hapi@18
+  - HAPI=@hapi/hapi@18
+  - HAPI=@hapi/hapi@19
+matrix:
+  exclude:
+  - node_js: 8
+    env: HAPI=@hapi/hapi@19
+  - node_js: 10
+    env: HAPI=@hapi/hapi@19
 before_script:
   - npm install --save-dev $HAPI
 after_script:
diff --git a/index.js b/index.js
index da08fb7..690b878 100644
--- a/index.js
+++ b/index.js
@@ -107,8 +107,10 @@ async function register (server, options) {
       return
     }
 
-    const childBindings = getChildBindings(request)
-    request.logger = request.logger || logger.child(childBindings)
+    if (!request.logger) {
+      const childBindings = getChildBindings(request)
+      request.logger = logger.child(childBindings)
+    }
 
     if (event.error && isEnabledLogEvent(options, 'request-error')) {
       request.logger.error(
@@ -129,6 +131,12 @@ async function register (server, options) {
     }
 
     const info = request.info
+
+    if (!request.logger) {
+      const childBindings = getChildBindings(request)
+      request.logger = logger.child(childBindings)
+    }
+
     request.logger.info(
       {
         payload: options.logPayload ? request.payload : undefined,


Test patch:
diff --git a/test.js b/test.js
index b3b032a..724fe2f 100644
--- a/test.js
+++ b/test.js
@@ -356,6 +356,34 @@ experiment('logs each request', () => {
 
     expect(options).to.equal(optionsClone)
   })
+
+  test('handles removed request.logger', async () => {
+    const server = getServer()
+
+    let done
+
+    const finish = new Promise(function (resolve, reject) {
+      done = resolve
+    })
+
+    server.route({
+      path: '/',
+      method: 'GET',
+      handler: async (req, h) => {
+        req.logger = undefined
+        return 'hello world'
+      }
+    })
+
+    await registerWithSink(server, 'info', data => {
+      expect(data.res.statusCode).to.equal(200)
+      expect(data.msg).to.equal('request completed')
+      done()
+    })
+
+    await server.inject('/')
+    await finish
+  })
 })
 
 experiment('logs through server.log', () => {