[]() []() []() [",
"1": "at outer (http://localhost:1337/test/test.js:2:3)",
"2": "at http://localhost:1337/test/test.js:9:1"
}
}
#### Server (NodeJS)
Fetch the latest version of console.history:`shell`
npm install console.history`js`
require('console.history')
console.log('Hello World!')console.history
At this point, the array is populated with one entry:`js`
[
{
type: 'log',
timestamp: 'Thu, 16 Mar 2017 17:24:25 GMT',
arguments: { '0': 'Hello World!' },
stack: [
'at Console.console._intercept (/.../console.history/test/node.js:4:11)',
'at Object.
'at Module._compile (module.js:571:32)',
'at Object.Module._extensions..js (module.js:580:10)',
'at Module.load (module.js:488:32)',
'at tryModuleLoad (module.js:447:12)',
'at Function.Module._load (module.js:439:3)',
'at Module.runMain (module.js:605:10)'
]
}
]
#### Intercepting the log function
You can add your own middleware to console.history with the function console._intercept(type, args). This can prove useful when you need to access a new log entry before or after it gets logged and added to the history array. See an example below.
`js
console._intercept = function (type, args) {
if (type === 'error') {
// send the error to your server or do something else..
}
// pass the log intent to the collector.
console._collect(type, args)
}
`
#### Limitations
Every saved console log is stored locally in the array console.history. A page reload will erase all history, as the array is not permanently stored. You could use localStorage or sessionStorage for that.
functions. Every call gets intercepted, printed and added to the history array.
console-history.js with in-line comments explaining the code.$3
If you'd like to contribute to console.history, or file a bug or feature request, please head over to the issue tracker or open a pull request.jekyll serve in the project's directory, navigating to localhost:4000/test in your browser and opening DevTools.
`shell
git clone https://github.com/lesander/console.history.git
cd console.history
jekyll serve
``The software is provided as is. It might work as expected - or not.
Just don't blame me.