fastify.log is undefined

Created on 15 Nov 2017  路  3Comments  路  Source: fastify/fastify

I just follow the doc: https://github.com/fastify/fastify/blob/master/docs/Getting-Started.md

start a server.js:

```
// Require the framework and instantiate it
const fastify = require('fastify')()

// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen(3000, function (err) {
if (err) throw err
fastify.log.info(server listening on ${fastify.server.address().port})
})


but throw the error: **TypeError: Cannot read property 'info' of undefined**

Then add the option : {logger: true}

 ```
// Require the framework and instantiate it
const fastify = require('fastify')({logger: true})

// Declare a route
fastify.get('/', function (request, reply) {
  reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen(3000, function (err) {
  if (err) throw err
  fastify.log.info(`server listening on ${fastify.server.address().port}`)
})

the error still happen, i read the other docs, find the server.js below is work!

// Require the framework and instantiate it
const log = require('pino')({ level: 'info' })
const fastify = require('fastify')({logger: true})

// Declare a route
fastify.get('/', function (request, reply) {
  request.log.info('here');
  reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen(3000, function (err) {
  if (err) throw err
  log.info(`server listening on ${fastify.server.address().port}`)
})

Is there something else i missed or there is something wrong with the docs?

question

Most helpful comment

The issue is that the documentation is tied to the latest on the master branch. The docs are referring to a breaking change merged by #436 that hasn't been published as a release yet. So you will need to reference fastify.logger for now.

cc: @delvedor @mcollina

All 3 comments

The issue is that the documentation is tied to the latest on the master branch. The docs are referring to a breaking change merged by #436 that hasn't been published as a release yet. So you will need to reference fastify.logger for now.

cc: @delvedor @mcollina

we need to do a release.

3ks, i know @jsumners, @mcollina

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

avilang picture avilang  路  3Comments

moltar picture moltar  路  3Comments

allevo picture allevo  路  3Comments

rqbazan picture rqbazan  路  3Comments