Roarr Fastify

Roarr Fastify compatible logger.
Motivation
- To have all logs produced using Roarr associated with the request ID.
- To use a single logging mechanism for HTTP service and the rest of the application.
Usage
import {
Roarr,
} from 'roarr';
import {
createFastifyLogger,
} from '@roarr/fastify';
import createFastify from 'fastify';
const log = Roarr.child({
program: 'your-program-name',
});
const app = createFastify({
logger: createFastifyLogger(log),
});
app.addHook('preHandler', (request, reply, done) => {
void log.adopt(
() => {
done();
},
{
requestId: request.id,
},
);
});
app.get('/', (request) => {
request.log.info('foo');
log.info('bar');
});
Configuration
If you have customized requestIdLogLabel setting in Fastify, then you also need to pass it to @roarr/fastify:
const app = createFastify({
logger: createFastifyLogger(log, {
requestIdLogLabel: 'requestId'
}),
requestIdLogLabel: 'requestId'
});