Socket
Socket
Sign inDemoInstall

callsite-record

Package Overview
Dependencies
22
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    callsite-record

Create fancy call site records for any function up in the stack for the logging purposes.


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

Readme

Source

callsite-record

Build Status

Create fancy call site records for any function up in the stack for the logging purposes.

'use strict';

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

let record = null;

function func1 () {
    record = createCallsiteRecord('func1');
}

(function func2(){
    func1();
})();

console.log(record.renderSync());

example

Install

npm install callsite-record

API

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:

console.log(record.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.render({ frameSize: 0 }));
// > 12 |    func1();
// ...

console.log(record.render({ 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 - V8 CallSite object.
  • idx - index of the frame.

Default: null.

Example:

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

// Remove node core lib calls from the stack trace
record.render({ 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.render({ renderer: defaultRenderer });
renderers.noColor

Same as default renderer but without colors.

Usage:

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

record.render({ 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.render({ renderer: html });
CallsiteRecord.renderSync([renderOptions]) → String

Sync version of the CallsiteRecord.render.

Author

Ivan Nikulin (ifaaan@gmail.com)

Keywords

FAQs

Last updated on 16 Feb 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