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

Return line of log #110

Closed
rudemex opened this issue Aug 26, 2020 · 1 comment
Closed

Return line of log #110

rudemex opened this issue Aug 26, 2020 · 1 comment

Comments

@rudemex
Copy link

rudemex commented Aug 26, 2020

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

Describe the solution you'd like
Solution in signale.js

get filename() {
    const _ = Error.prepareStackTrace;
    Error.prepareStackTrace = (error, stack) => stack;
    const {stack} = new Error();
    Error.prepareStackTrace = _;

    const callers = stack.map(x => x.getFileName());
    const callersAndLines = stack.map( x => ({"filename": x.getFileName(), "line": x.getLineNumber()}));

    const firstExternalFilePath = callers.find(x => {
      return x !== callers[0];
    });

    const filenameAndLine = callersAndLines.find( x => {
      return x.filename !== callers[0];
    });
    
    return firstExternalFilePath ? `${path.basename(filenameAndLine.filename)} - Line: ${filenameAndLine.line}` : 'anonymous';
  }

Additional context
Add any other context or screenshots about the feature request here.
image

@rudemex
Copy link
Author

rudemex commented Aug 26, 2020

Implemented in => #112

@rudemex rudemex closed this as completed Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant