package
Add console functions that also output where the call was made.
npm install console-atGitHub-flavored package documentation.
Across all versions, last 30 days.
26 in 30 days
Runtime metadata.
Tagged topics.
Add console functions that also output where the call was made.
The console object has several useful functions defined as properties. Because functions are not primitive we can add properties to those functions. For each of the following functions, an at property is added that is called using the same parameters. It calls the original function plus adds information about where the function was called.
These functions each have the at property added to them just by requiring the console-at package once in your project:
Example 1
This still works.
require('console-at');
console.log('Hello, World!');
// Hello, World!Example 2
We can also call the log function with location information:
require('console-at');
console.log.at('Hello, World!');
// Hello, World!
// at /path/to/file.js: 2$ npm install console-atThe package includes a single function that can be called to determine the location that the function is called at. Additionally this function can take an optional parameter that will specify how far back in the stack to look for location information.
Parameters
0.Returns an object with the following properties:
Example 1: Zero Depth
var at = require('console-at');
function foo() {
return at(); // the position reported is here
}
console.log(foo());
/*
{ column: 12,
file: '/path/to/file.js',
line: 4,
method: 'foo',
position: 120,
source: '/path/to/file.js:4' }
*/Example 2: One Depth
var at = require('./index');
function foo() {
return at(1);
}
var source = foo(); // the position reported is here
console.log(source);
/*
{ column: 14,
file: '/path/to/file.js',
line: 7,
method: null,
position: 143,
source: '/path/to/file.js:7' }
*/