klaudiosinani / signale

Highly configurable logging utility
MIT License
8.93k stars 232 forks source link

Return line of log #110

Closed rudemex closed 4 years ago

rudemex commented 4 years ago

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 commented 4 years ago

Implemented in => https://github.com/klaussinani/signale/pull/112