All Projects â†’ lesander â†’ console.history

lesander / console.history

Licence: MIT license
📜 Store all javascript console logs in console.history

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
HTML
75241 projects

Projects that are alternatives of or similar to console.history

Filter Console
Filter out unwanted `console.log()` output
Stars: ✭ 203 (+576.67%)
Mutual labels:  console, npm-package
Chalk Animation
🎬 Colorful animations in terminal output
Stars: ✭ 1,489 (+4863.33%)
Mutual labels:  console, npm-package
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (+76.67%)
Mutual labels:  console, history
ansicolor
A JavaScript ANSI color/style management. ANSI parsing. ANSI to CSS. Small, clean, no dependencies.
Stars: ✭ 91 (+203.33%)
Mutual labels:  console, npm-package
mongo-gui
A web-based MongoDB graphical user interface
Stars: ✭ 111 (+270%)
Mutual labels:  npm-package
portera
Remote logs
Stars: ✭ 22 (-26.67%)
Mutual labels:  console
tinydownloader
a tiny downloader with console panel.
Stars: ✭ 80 (+166.67%)
Mutual labels:  console
v-svg-icons
Svg icons for VueJS.
Stars: ✭ 36 (+20%)
Mutual labels:  npm-package
react-circle-flags
🚀 A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (-3.33%)
Mutual labels:  npm-package
ansiart2utf8
Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8. Escape codes and line endings are processed for terminal friendliness.
Stars: ✭ 32 (+6.67%)
Mutual labels:  console
youtrack-cli
Command Line Tool for interacting with youtrack
Stars: ✭ 14 (-53.33%)
Mutual labels:  npm-package
cliptext
Clipboard manager for macOS. Built with Electron.js
Stars: ✭ 37 (+23.33%)
Mutual labels:  history
browserexport
backup and parse browser history databases (chrome, firefox, safari, and other chrome/firefox derivatives)
Stars: ✭ 54 (+80%)
Mutual labels:  history
react-folder-tree
A versatile react treeview library that supports custom icons and event handlers
Stars: ✭ 56 (+86.67%)
Mutual labels:  npm-package
titanium-angular
Use the Titanium platform with Angular
Stars: ✭ 16 (-46.67%)
Mutual labels:  npm-package
jsdoc-api
A programmatic interface for jsdoc3 with a few extra features
Stars: ✭ 55 (+83.33%)
Mutual labels:  npm-package
xontrib-prompt-bar
The bar prompt for xonsh shell with customizable sections and Starship support.
Stars: ✭ 27 (-10%)
Mutual labels:  console
React-Pincode
A NPM module which auto fills City, District and State fields when a valid Zip Code in entered!
Stars: ✭ 26 (-13.33%)
Mutual labels:  npm-package
nim-dashing
Terminal dashboards for Nim
Stars: ✭ 105 (+250%)
Mutual labels:  console
EverydayFun
A simple NPM package which can return everyday quotes, jokes, riddles and interesting facts!
Stars: ✭ 35 (+16.67%)
Mutual labels:  npm-package

console.history

npm GitHub release npm Code Climate BCH compliancy Build Status

A very small library to store all console logs in console.history.

Usage

Include console-history.js or console-history.min.js in your page or script before any console function gets called. All calls to console.log, console.info, console.warn, console.error and console.debug will be intercepted and stored after doing so. Including every parameter passed to those functions.

Getting Started

This library works in almost all browsers and on any NodeJS server.

Browser

You can download the latest release on GitHub, or use jsDelivr's CDN to get the latest version directly in your browser:

<script src="https://cdn.jsdelivr.net/gh/lesander/[email protected]/console-history.min.js"></script>

See an example entry to the history array below. This example is from the test/test.js file.

{
  "type": "warn",
  "timestamp": "Thu, 01 Sep 2016 15:38:28 GMT",
  "arguments": {
    "0": "Something went wrong, but we're okay!"
  },
  "stack": {
    "0": "at inner (http://localhost:1337/test/test.js:6:11)",
    "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:

npm install console.history
require('console.history')
console.log('Hello World!')

At this point, the console.history array is populated with one entry:

[
  {
    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.<anonymous> (/.../console.history/test/node.js:6:9)',
      '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.

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.

How it works

This script is basically a man-in-the-middle for all console[log/info/warn/error/debug] functions. Every call gets intercepted, printed and added to the history array.

The code is not that hard to understand, see console-history.js with in-line comments explaining the code.

Contributing

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.

Testing browser-side is as easy as running jekyll serve in the project's directory, navigating to localhost:4000/test in your browser and opening DevTools.

git clone https://github.com/lesander/console.history.git
cd console.history
jekyll serve

License

This software is open-sourced under the MIT License (see the LICENSE file for the full license). So within some limits, you can do with the code whatever you want. However, if you like and/or want to re-use it, I'd really appreciate a reference to this project page.

The software is provided as is. It might work as expected - or not. Just don't blame me.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].