Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend function name and line number to debug message #343

Closed
hutch120 opened this issue Dec 9, 2016 · 2 comments
Closed

Prepend function name and line number to debug message #343

hutch120 opened this issue Dec 9, 2016 · 2 comments
Labels
wont-fix This is not a feature or proposal that will be incorporated, or a bug that won't be addressed

Comments

@hutch120
Copy link

hutch120 commented Dec 9, 2016

Hi All,

Love this project! Sorry if this has already been covered... I did take a look at the issue list and found mostly people saying not implemented, or suggesting browser related solutions. I'm working in NodeJS, and having a function name and line number on each debug message really helps development efforts.

I'm wondering what the implications of adding the following which I've just started using in a recent NodeJS project? Especially the use of arguments.callee which I've read is depreciated. Is there an alternative?

I would love to be able to turn this on as an option, rather than have to append it to every debug message as shown below.

const debug = require('debug')('MyApp:MyModule')
debug(__dstring + "My debug message")

Outputs: MyApp:MyModule myFunction 44 My debug message

__dstring is defined like this:

Object.defineProperty(global, '__dstring', {
  get: function () {
    try {
      var orig = Error.prepareStackTrace;
      Error.prepareStackTrace = function (_, stack) {
        return stack;
      };
      var err = new Error;
      Error.captureStackTrace(err, arguments.callee);
      var stack = err.stack;
      Error.prepareStackTrace = orig;
      return stack[1].getMethodName() + " " + stack[1].getLineNumber() + " ";
    } catch (err) {
      return ""
    }
  }
});

References:
http://stackoverflow.com/questions/11386492/accessing-line-number-in-v8-javascript-chrome-node-js

@likun7981
Copy link

likun7981 commented Dec 13, 2016

how about #346

@thebigredgeek
Copy link
Contributor

#370 < seems like a solid case for V3 middleware API :). Feel free to jump into the conversation

@thebigredgeek thebigredgeek added the wont-fix This is not a feature or proposal that will be incorporated, or a bug that won't be addressed label Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wont-fix This is not a feature or proposal that will be incorporated, or a bug that won't be addressed
Development

No branches or pull requests

3 participants