I use Morgan and Express to provide REST APIs for my website. I implementet the morgan-logger this way in my main.js:
app.use(morgan('dev')); //logger
app.use(morgan('dev', {stream: fs.createWriteStream('./access.log', {flags:
'a'})}));
Now it logs me every call to an API in my access.log file like this:
::ffff:10.60.101.165 - - [26/Feb/2019:08:19:57 +0000] "POST /api/api1
HTTP/1.1" 200 -
::ffff:10.60.101.165 - - [26/Feb/2019:08:19:58 +0000] "POST /api/api2
HTTP/1.1" 200 -
::ffff:10.60.101.165 - - [26/Feb/2019:08:19:58 +0000] "POST /api/api3
HTTP/1.1" 200 -
Thats fine, but when I write own log messages like console.log("error in file A"), it is printed in the console but not in my access.log file. How can I write manually to it inside my API file?