I'm handling a new project with node.js backend and my morgan
logger works quite wired. At first I was unable to get any output from it using any of predefined morgan templates (tiny
, short
, e.c.t) nothing was propagated to output. I provided custom logging function to verify does the morgan is called at all on my stack:
app.use(morgan((tokens, req, res) => {
console.log('AAAAAAAAAAA');
return 'ABABABABABAA';
}, { stream: process.stdout }));
Sequence of AAAAAAAAAAA
is indeed propagated to console output via console.log
inside logging function (proof that morga in actually called on each request), but logging function does not provide it's ABABABABABA
sequence at all.
As long as I'm able to imagine that predefined format may fail due to non-conventional names of req
/res
objects (which is by the way not a case), then returning plain text from logger function shall be obviously propagated to output straight through.
Edit
Setting morgan option to {immediate: true}
also does not resolve issue.