How do I install bunyan logger so that on the routes they can get children of bunyan for their own loggers?
Attempt:
import * as restify from 'restify';
import {createLogger} from 'bunyan';
let app = restify.createServer();
app.use(restify.queryParser());
app.use(restify.bodyParser());
app.on('after', restify.auditLogger({
log: createLogger({
name: 'audit',
stream: process.stdout
})
}));
app.get('/foo', (req, res, next) => {
req.getLogger('foo').info('bar');
res.json({});
});
app.listen(process.env.PORT || 3000, function() {
console.info('%s listening at %s', app.name, app.url);
});
req.getLogger
should work as per http://restify.com/#getloggercomponent, but maybe there's an app.use
step also required, but not mentioned in the docs?
Here is how I did it in a recent application.
Then, wherever you have access to the request object you just use it like this.