Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

payload is not recorded using the example #1

Closed
azuruce opened this issue Dec 4, 2014 · 1 comment
Closed

payload is not recorded using the example #1

azuruce opened this issue Dec 4, 2014 · 1 comment

Comments

@azuruce
Copy link

azuruce commented Dec 4, 2014

I don't see the payload.

@silas
Copy link
Owner

silas commented Dec 9, 2014

Yup, none of the hapi events include the payload. Also because the payload might be something that isn't json friendly (like a big video or something), logging it by default doesn't really make any sense.

You could easily do this yourself if you wanted, something like the follow would work with the latest version of hapi.

var bunyan = require('bunyan');
var hapi = require('hapi');

var server = new hapi.Server();
server.connection({ port: 8000 });

server.route({
  method: 'GET',
  path: '/',
  handler: function(request, reply) {
    request.log.info('just a test');

    reply({ hello: 'world' });
  },
});

var config = {
  register: require('./lib'),
  options: {
    logger: bunyan.createLogger({ name: 'test', level: 'debug' }),
  },
};

server.register(config, function(err) {
  if (err) throw err;
});

server.ext('onPreResponse', function(request, reply) {
  if (request.response.variety === 'plain' && request.response.source) {
    request.log.info({ body: request.response.source });
  }

  reply.continue();
});

server.start();

@silas silas closed this as completed Dec 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants