Repository: fastify/fastify
File: test/logger/instantiation.test.js (JavaScript)

Code before:
  })

  t.test('can use external logger instance', async (t) => {
    const lines = [/^Server listening at /, /^incoming request$/, /^log success$/, /^request completed$/]
    t.plan(lines.length + 1)

    const stream = split(JSON.parse)

    const logger = require('pino')(stream)

    const fastify = Fastify({ logger })
    t.teardown(fastify.close.bind(fastify))

    fastify.get('/foo', function (req, reply) {
      t.ok(req.log)
      req.log.info('log success')
      reply.send({ hello: 'world' })
    })

    await fastify.listen({ port: 0, host: localhost })

    await request(`http://${localhostForURL}:` + fastify.server.address().port + '/foo')

    for await (const [line] of on(stream, 'data')) {
      const regex = lines.shift()
      t.ok(regex.test(line.msg), '"' + line.msg + '" don\'t match "' + regex + '"')
      if (lines.length === 0) break
    }
  })

  t.test('should create a default logger if provided one is invalid', (t) => {
    t.plan(8)

    const logger = new Date()

    const fastify = Fastify({ logger })
    t.teardown(fastify.close.bind(fastify))

    t.equal(typeof fastify.log, 'object')
    t.equal(typeof fastify.log.fatal, 'function')
    t.equal(typeof fastify.log.error, 'function')
    t.equal(typeof fastify.log.warn, 'function')
    t.equal(typeof fastify.log.info, 'function')
    t.equal(typeof fastify.log.debug, 'function')
    t.equal(typeof fastify.log.trace, 'function')
    t.equal(typeof fastify.log.child, 'function')
  })

  t.test('expose the logger', async (t) => {
    t.plan(2)
    const stream = split(JSON.parse)

Review comment (suggestion):
```suggestion
      t.ok(regex.test(line.msg), '"' + line.msg + '" does not match "' + regex + '"')
```

Code after:
  })

  t.test('can use external logger instance', async (t) => {
    const lines = [/^Server listening at /, /^incoming request$/, /^log success$/, /^request completed$/]
    t.plan(lines.length + 1)

    const stream = split(JSON.parse)

    const logger = require('pino')(stream)

    const fastify = Fastify({ logger })
    t.teardown(fastify.close.bind(fastify))

    fastify.get('/foo', function (req, reply) {
      t.ok(req.log)
      req.log.info('log success')
      reply.send({ hello: 'world' })
    })

    await fastify.listen({ port: 0, host: localhost })

    await request(`http://${localhostForURL}:` + fastify.server.address().port + '/foo')

    for await (const [line] of on(stream, 'data')) {
      const regex = lines.shift()
      t.ok(regex.test(line.msg), '"' + line.msg + '" does not match "' + regex + '"')
      if (lines.length === 0) break
    }
  })

  t.test('should create a default logger if provided one is invalid', (t) => {
    t.plan(8)

    const logger = new Date()

    const fastify = Fastify({ logger })
    t.teardown(fastify.close.bind(fastify))

    t.equal(typeof fastify.log, 'object')
    t.equal(typeof fastify.log.fatal, 'function')
    t.equal(typeof fastify.log.error, 'function')
    t.equal(typeof fastify.log.warn, 'function')
    t.equal(typeof fastify.log.info, 'function')
    t.equal(typeof fastify.log.debug, 'function')
    t.equal(typeof fastify.log.trace, 'function')
    t.equal(typeof fastify.log.child, 'function')
  })

  t.test('expose the logger', async (t) => {
    t.plan(2)
    const stream = split(JSON.parse)