4

I've gathered that due to the event queue design of node.js and the way that JavaScript references work, that there's not an effective way of figuring out which active request object (if any) spawned the currently-executing function.

If I am in fact mistaken, how do I maintain some sort of statically-accessible context object that is available for the life of a request, short of manually passing it around every function in the event/callback chain?

If there's no way to do that, is there a way to somehow wrap every event call so that when it is spawned, it copies the context data from the event that spawned it?

What I'm actually trying to achieve is having every log message also contain the username of the person to whom the log message is related. Because the callback event chain can become quite complex, I'd say trying to pass the request object around every function in the application is a bit messy for my taste, so hopefully there's another way.

Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
  • 1
    I just answered a similar question here: http://stackoverflow.com/a/11814601/1577019 – Matt Smith Aug 05 '12 at 07:15
  • possible duplicate of [Node.js Programming Pattern for getting Execution Context](http://stackoverflow.com/questions/9924465/node-js-programming-pattern-for-getting-execution-context) – Nathan Ridley Aug 05 '12 at 10:17

0 Answers0