-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Log caller function name and line number #890
Comments
hi, I am trying to use your wrapper right now and get this error:
Any idea how I could resolve this? |
Try Easylogging++ binding for node. See original library docs to check the potential of this binding A simple example
|
In the line |
I used @httpdigest solution to create a Static class for what I needed but you can use it as above with winston
export
I split it to 2 classes to only expose the intended function on the static class I ended up here as I got stuck with the
when trying to use |
Thanks for the suggestion @httpdigest! But as you said this is a duplicate of #200, so going to close it. Will leave the issue unlocked to keep the discussion going this time. |
please provide a option to enable this feature, like log4js |
There does not seem to be a way to log the caller's method name and line number. I know that this has already been requested with #200, but that issue was locked with the reason that such a function would be very slow. Given that a typical application would not excessively log thousands of log statements per second, it does not make a noticeably difference.
As you probably know, JavaScript provides the stack trace in the
Error.stack
property on construction of a new Error object. However, this is an unstructured string and needs to be parsed.V8 on the other hand has a feature allowing to retrieve the stack trace in its original structured form (before stringifying). This is described here: https://github.com/v8/v8/wiki/Stack-Trace-API
My current implementation on top of Winston looks like this. (It may not be a good implementation, I'm very new to JavaScript and Node/V8. :) )
Credits go to @addaleax from: nodejs/node#7749 (comment)
The way the string is formatted and the module exports are defined, sure needs reworking, I guess.
This ticket could serve as a discussion on how a good PR would look like for Winston, adding this feature to the library.
The text was updated successfully, but these errors were encountered: