How to use the stack-trace.get function in stack-trace

To help you get started, we’ve selected a few stack-trace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microclimate-dev2ops / microclimate-vscode-tools / dev / src / Logger.ts View on Github external
private static getCaller(): string {
        // get the stack trace above logInner. casting is necessary because the stack trace package only accepts () => void functions.
        const stack = Stacktrace.get(Log.logInner as unknown as () => void);
        // 6 frames is the magic number to get around __awaiters, past the Log.x function, and up to the frame we care about.
        const frame = stack[6];
        if (frame == null) {
            return "N/A";
        }

        let methodName = frame.getMethodName() || frame.getFunctionName();
        if (methodName != null) {
            // If it's a callback, there will be extra stuff we aren't interested in separated by dots
            // eg "Project.__dirname.constructor.connection.update"
            // strip out everything up to the last dot, if there is one
            const splitByPeriod: string[] = methodName.split(".");
            if (splitByPeriod.length > 1) {
                methodName = splitByPeriod[splitByPeriod.length - 1];
            }
            methodName = `.${methodName}()`;
github thenativeweb / flaschenpost / lib / Middleware / index.js View on Github external
constructor (level, source) {
    if (!level) {
      throw new Error('Level is missing.');
    }

    /* eslint-disable global-require */
    const flaschenpost = require('../flaschenpost');
    /* eslint-enable global-require */

    const options = {};

    options.objectMode = true;
    options.source = source || stackTrace.get()[1].getFileName();

    super(options);

    this.level = level;
    this.logger = flaschenpost.getLogger(options.source);

    if (!this.logger[this.level]) {
      throw new Error('Level is invalid.');
    }
  }
github di-ninja / di-ninja / src / nodeRequireContext.js View on Github external
export default function (folder, recursive = false, pattern = patternDefault, parentDir = undefined) {
  folder = path.normalize(folder)
  if (!parentDir) {
    parentDir = path.dirname(stackTrace.get()[1].getFileName())
  }
  const contextDir = path.join(parentDir, folder)
  const contextDirLen = contextDir.length + 1
  const normalizedFolder = path.resolve(parentDir, folder)
  const folderContents = getFolderContents(normalizedFolder, recursive)
    .filter(item => {
      return pattern.test(item)
    })
    .map(item => {
      return '.' + SEP + item.substr(contextDirLen)
    })

  const keys = function () {
    return folderContents
  }
github atomist / automation-client / lib / graph / ApolloGraphClient.ts View on Github external
public mutate(options: MutationOptions<q> | string): Promise {
        if (typeof options === "string") {
            options = {
                name: options,
            };
        }
        const m = internalGraphql.mutate({
            mutation: options.mutation,
            path: options.path,
            name: options.name,
            moduleDir: (options as any).moduleDir ? (options as any).moduleDir : trace.get()[1].getFileName(),
        });
        return this.executeMutation(m, options.variables, options.options);
    }
</q>
github seanmonstar / insist / insist.js View on Github external
function getMessage() {
  var trace = stack.get()[2];
  var fileName = trace.getFileName();
  if (fileName !== 'repl') {
    return getSource(trace);
  } else {
    return trace.fun.toString();
  }
}
github megahertz / gulp-task-doc / lib / parser.js View on Github external
exports.makeTaskInfo = function getTaskInfo(name, calleeOffset) {
  calleeOffset = undefined !== calleeOffset ? calleeOffset : 2;
  var trace = stackTrace.get();
  var gulpFile = trace[calleeOffset];
  if (!gulpFile) {
    return null;
  }
  
  return {
    name: name,
    file: gulpFile.getFileName(),
    line: gulpFile.getLineNumber()
  };
};
github pixelsandbytes / caller-id / lib / caller-id.js View on Github external
function getData(func) {
    var trace = stackTrace.get(func || getCaller(getData));
    var caller = trace[0];
    return {
        typeName: caller.getTypeName(),
        functionName: caller.getFunctionName(),
        methodName: caller.getMethodName(),
        filePath: caller.getFileName(),
        lineNumber: caller.getLineNumber(),
        topLevelFlag: caller.isToplevel(),
        nativeFlag: caller.isNative(),
        evalFlag: caller.isEval(),
        evalOrigin: caller.getEvalOrigin()
    };
}
github RocketChat / Rocket.Chat.Apps-engine / src / server / logging / AppConsole.ts View on Github external
public error(...items: Array): void {
        this.addEntry(LogMessageSeverity.ERROR, this.getFunc(stackTrace.get()), ...items);
    }
github caolan / jam / node_modules / prompt / node_modules / winston / lib / winston / exception.js View on Github external
exception.getTrace = function (err) {
  var trace = err ? stackTrace.parse(err) : stackTrace.get();
  return trace.map(function (site) {
    return {
      column:   site.getColumnNumber(),
      file:     site.getFileName(),
      function: site.getFunctionName(),
      line:     site.getLineNumber(),
      method:   site.getMethodName(),
      native:   site.isNative(),
    }
  });
};
github xiaodoudou / PlexIPTV / logger.js View on Github external
template (logLevel, data) {
    const trace = stackTrace.get()
    trace.splice(0, 2)
    let methodName = ''
    _.forEach(trace, (item) => {
      if (item.getFunctionName() != null) {
        methodName = item.getFunctionName()
        return false
      }
    })
    methodName = colors.green(methodName)
    if (logLevel == null) { logLevel = this._trace }
    const prefix = `${this.timestamp()} ${logLevel.prefix} ${methodName}`
    if (_.isArray(data) && data.length === 1) { data = _.first(data) }
    if (_.isString(data)) {
      logLevel.instance('%s %s', prefix, data)
    } else {
      if (_.isString(_.first(data))) {

stack-trace

Get v8 stack traces as an array of CallSite objects.

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis

Popular stack-trace functions