Socket
Socket
Sign inDemoInstall

callsite-record

Package Overview
Dependencies
6
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    callsite-record

Create fancy log entries for errors and function call sites.


Version published
Weekly downloads
429K
increased by2.02%
Maintainers
1
Install size
1.99 MB
Created
Weekly downloads
 

Readme

Source

callsite-record

Build Status

Create fancy log entries for errors and function call sites.

For Error:

'use strict';

const createCallsiteRecord = require('callsite-record');

function myFunc() {
    throw new Error('Yo!');
}

try {
    myFunc();
}
catch(err) {
    console.log(createCallsiteRecord(err).renderSync());
}

example

For function call up in the stack:

'use strict';

const createCallsiteRecord = require('callsite-record');

function func2 () {
    (function func1 () {
        console.log(createCallsiteRecord('func2').renderSync());
    })();
}

func2();

example

Additional goodies:

  • Use renderers for different output formats, e.g. to produce output in HTML.
  • Use stack filter to produce clean and beautiful stacks, e.g. removing Node lib internal calls.

Install

npm install callsite-record

API

createCallsiteRecord(error) → CallsiteRecord

Creates CallsiteRecord for error.

Example:

const createCallsiteRecord = require('callsite-record');

try {
    throw new Error("We're doomed");
}
catch(err) {
    const record = createCallsiteRecord(err);
}

createCallsiteRecord(functionName, [typeName]) → CallsiteRecord

Creates CallsiteRecord for the function up in the call stack specified by functionName. You can optionally specify a typeName if the function is a method. If the function is a constructor set functionName to constructor.

Example:

const createCallsiteRecord = require('callsite-record');

(function func1() {
    (function func2() {
        (function func3() {
            const record = createCallsiteRecord('func2');
        })();
    })();
})();

CallsiteRecord

CallsiteRecord.render([renderOptions]) → Promise<String>

Renders call site record to the string.

Example:

record.render().then(str => console.log(str));
CallsiteRecord.renderSync([renderOptions]) → String

Sync version of the CallsiteRecord.render.

renderOptions.frameSize

Specifies the number of lines rendered above and below the call site in the code frame. Default: 5.

Example:

console.log(record.renderSync({ frameSize: 0 }));
// > 12 |    func1();
// ...

console.log(record.renderSync({ frameSize: 1 }));
//   11 |(function func2() {
// > 12 |    func1();
//   13 |})();
// ...
renderOptions.stack

Specifies if stack trace should be rendered in addition to the code frame. Default: true.

renderOptions.stackFilter

Function that will be used to filter stack frames. Function accepts 2 arguments:

  • stackFrame - stack entry.
  • idx - index of the frame.
  • isV8StackFrame - if true then stackFrame is a V8 CallSite object. Otherwise it's a StackFrame object.

Default: null.

Example:

const sep = require('path').sep;

// Remove node core lib calls from the stack trace
record.renderSync({ stackFilter: frame => frame.getFileName().indexOf(sep) > -1 });
renderOptions.renderer

Specifies the output format of the rendering. Default: renderers.default. You can pass your own renderer object (example implementations) or use one of the built-in renderers:

renderers.default

Provides ANSI-colored output as shown above.

Usage:

const defaultRenderer = require('callsite-record').renderers.default;

record.renderSync({ renderer: defaultRenderer });
renderers.noColor

Same as default renderer but without colors.

Usage:

const noColorRenderer = require('callsite-record').renderers.noColor;

record.renderSync({ renderer: noColorRenderer });
renderers.html

Outputs HTML that can be later decorated with the CSS and embeded into the web page. Example output.

Usage:

const htmlRenderer = require('callsite-record').renderers.html;

record.renderSync({ renderer: html });

Author

Ivan Nikulin (ifaaan@gmail.com)

Keywords

FAQs

Last updated on 04 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc