Per request logging in Node.js

前端 未结 3 938
轻奢々
轻奢々 2021-02-13 00:46

I am an experienced Java developer picking up Node.js and making the shift to the asynchronous model. Most things are going fine except for logging. I cannot find anything sim

3条回答
  •  天命终不由人
    2021-02-13 01:24

    Answering this as I just wrote a post on how to use continuation-local-storage to save a "transaction id" with every log (without manually propagating it). You can do the same for the client ip, process id, etc.

    Follow this post: https://datahero.com/blog/2014/05/22/node-js-preserving-data-across-async-callbacks/

    But instead of just saving a transaction id, you'll want these as well: request.connection.remoteAddress and process.pid

    Let me know if you have any questions here or there, and I'll answer them.

提交回复
热议问题