Code Monkey home page Code Monkey logo

consopretty's Introduction

npm version

Con-SO-Pretty!

Node console.log sexification.

Install

npm i conso-pretty

TL;DR

Easy and extensible Node.js Console Coloring and Formatting. Uses RenderKid to make your log prinkle like diamond.

Example

const ConsoPretty = require('conso-pretty');
const cp = new ConsoPretty();
cp.start(true); //Pass true to bind ConsoPretty to console.log(), console.error() etc.

//Then just use your log as normal 
console.log("Test Render", {test: 1, object: 2, for: "util"});
console.error("Test Render", {test: 1, object: 2, for: "util"});
console.debug("Test Render", {test: 1, object: 2, for: "util"});
console.info("Test Render", {test: 1, object: 2, for: "util"});
console.warn("Test Render", {test: 1, object: 2, for: "util"});

All those magic parkles and prinkles!

Result

Example Output

Usage

There are 2 main methods ConsoPretty uses to output to the terminal:

1. Bind to Console

This is probably the only thing 95% of users will need. Using this method, ConsoPretty overrides the native console object so you can just log the way you normally do. References to the original console.[method] functions are saved and can be restored later. \

Example: Automatic Bind

cp.start({bind: true}); //Initialise ConsoPretty and pass bind: true to bind to console.log(), console.error() etc.


//Then just use your log as you normally would
console.log("Test Render", {test: 1, object: 2, for: "util"});
console.error("Test Render", {test: 1, object: 2, for: "util"});
console.debug("Test Render", {test: 1, object: 2, for: "util"});
console.info("Test Render", {test: 1, object: 2, for: "util"});
console.warn("Test Render", {test: 1, object: 2, for: "util"});

Example: Bind manually

cp.bind();

//Then just use your log as you normally would
console.log("Test Render", {test: 1, object: 2, for: "util"});
console.error("Test Render", {test: 1, object: 2, for: "util"});
console.debug("Test Render", {test: 1, object: 2, for: "util"});
console.info("Test Render", {test: 1, object: 2, for: "util"});
console.warn("Test Render", {test: 1, object: 2, for: "util"});

2. Restore original Console

If for some reason you need to restore the original console, you can call the restore() method.

Example

cp.bind();
console.log("Test Render", {test: 1, object: 2, for: "util"});
cp.restore();
console.log("Test Render", {test: 1, object: 2, for: "util"});

Outputs:

Example Output

3. Styling

cp.bind();
cp.setStyle({
    log: {
        "ts": {
            color: "magenta",
            marginRight: "1"
        },
        "key": {
            color: "bright-magenta",
            marginRight: "1"
        },
        "value": {
            color: "white"
        },
        "sep": {
            color: "bright-magenta"
        }
    }
});

//Turn off timestamping
cp.toggleTimestamp();

//Rebind console
console.log("Test Render", {test: 1, object: 2, for: "util"});
console.error("Test Render", {test: 1, object: 2, for: "util"});
console.debug("Test Render", {test: 1, object: 2, for: "util"});
console.info("Test Render", {test: 1, object: 2, for: "util"});
console.warn("Test Render", {test: 1, object: 2, for: "util"});

consopretty's People

Contributors

liamwhan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.