1.1.6 • Published 7 years ago

conso-pretty v1.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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"});
1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago