A simple logging utility that supports colors and custom log levels.
Inspired heavily by signale, this is a lightweight alternative with no dependencies.
Install
$ npm install purpzielog
Usage
const Logger = require("purpzielog");
const log = new Logger();
log
.info("Woah, these are chainable")
.error("Also,", "multiple things", "are grouped", "together.")
.warn("Foo")
.success("Bar")
.note("Remember to do the thing");
Creating custom log levels is super easy.
const log = new Logger({
foo: "blue",
bar: { label: "custom label", color: "yellow" },
blep: ["custom label", "yellow"], // same thing!
heck: "red & underline",
loud: input => input.toUpperCase()
});
log.foo("Blah blah blah");
log.bar("You can also customize labels!");
log.heck("You can define multiple colors/styles separated by '&'");
log.loud("custom functions too!");
Timers
let timer = log.time();
// ...time passes
log.timeEnd(timer, "It took %s to do stuff");
// It took 10.537ms to do stuff
You can also restart them instead of deleting them immediately by passing true
as the 3rd argument.
log.timeEnd(timer, "%s has passed", true); // 69.420ms has passed
// ...more time passes
log.timeEnd(timer, "%s has passed since the last msg");
// 70.243ms has passed since the last msg
timeEnd()
is also available on log levels.
log.debug.timeEnd(timer, "Time passed:");
// ❯ debug ─ Time passed: 5.234ms
And, if you need to get this time as a number instead of logging a message, timeGet()
is for you.
let ms = log.timeGet(timer); // 6.213
// You can pass 'true' as the second argument to restart the timer
License
MIT © Purpzie