First up, node is not my thing. Nevertheless I find myself trying to figure out how to combine pino/pino-http and express to deliver some formatted logs. This part I have achieved.
What I was attempting to figure out for a short while was how to pass express via app.use(logger) a logger object that has got some base properties injected into it.
I tried a bunch of stuff, including creating a child logger and passing that to pinoHTTP() but although that did not error, i'd end up getting very long log objects which seemed full of goop and undesirable content.
pseudo code
const express = require('express');
const pino = require('pino');
const log = pino({level: process.env.LOG_LEVEL || 'info'});
const childLogger = log.child({'exampleProp': 'example-value'});
const logger = require('pino-http')({
logger: childLogger
});
const app = express();
const port = 3000;
app.use(logger);
app.get('/', (req, res) => {
logger.info('Hello World');
res.send('Hello World!');
});
app.listen(port, () => {
console.log('Example app listening on port ${port}')
});