I want log every http request being made by a particular node app, and all of its modules. Wrapping requests in a function could work for all non-module code, the disadvantage would obviously be it doesn't include module code, and be cumbersome to do.
This is for apps already in production, only other option I thought of was tcpdump.
Express uses the debug module internally to log information about route matches, middleware functions that are in use, application mode, and the flow of the request-response cycle. debug is like an augmented version of console. log , but unlike console.
Some of the most popular logging libraries for Node are Winston, Pino, Bunyan, and Log4js. While you should almost always use a standard console. log, a logging library can be more functional and help avoid decreases in app performance.
Setting NODE_DEBUG=http
will make node log out detailed HTTP request information to the console.
Examples:
NODE_DEBUG=http node index.js
NODE_DEBUG=http npm start
For more information see:
NODE_DEBUG documentation
This blog post: Debugging tools and practices in node.js.
It includes:
List of the default available NODE_DEBUG attributes:
- timer
- http
- net
- fs
- cluster
- tls
- stream
- child_process
- module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With