2.2.3 • Published 10 months ago
@marianmeres/clog v2.2.3
@marianmeres/clog
On top of console.log. Mostly.
Tiny namespaced console wrapper with configurable silence switches (global or local). And with custom writer support.
Installation
Deno
deno add jsr:@marianmeres/clogNode
npm i @marianmeres/clogpnpm add @marianmeres/clogUsage
// create logger
const clog = createClog("foo");
// use any of the debug, info, log, warn, error (or none) methods
clog("bar", "baz"); // same as clog.log
clog.debug("bar", "baz");
clog.log("bar", "baz");
clog.info("bar", "baz");
clog.warn("bar", "baz");
clog.error("bar", "baz");
// 6 x output: [foo] bar baz
// example for errors only output (configured locally)
const clog = createClog("foo", { error: true });
clog("debug"); // ignored
clog.error("error");
// output: [foo] error
// example for global config silence
createClog.DISABLE = true;
clog("bar", "baz");
// output none
// to use clog without namespace, use `false`
createClog(false)("foo", "bar");
// output: foo bar
// to color the namespace label use `color` or the %c modifier
// these examples work in browser or deno (not in node)
clog("%cbar", "color:red");
clog.color("red")("bar");
// outputs "[foo] bar" where "[foo]" is in red (but not bar)
// you can automatically prepend time or dateTime
const clog = createClog("foo", { time: true });
clog("bar");
// outputs: [HH:MM:SS.mmm] [foo] bar
const clog = createClog("foo", { dateTime: true });
clog("bar");
// outputs: [YYYY-MM-DD HH:MM:SS.mmm] [foo] barCustom writer setup example
This creates colored output based on log level
import { gray, green, red, yellow } from "kleur/colors";
// somewhere in app bootstrap
const _setup = (k, c) => (...a) => console[k].apply(null, a.map((v) => c(v)));
createClog.WRITER = {
debug: _setup("debug", gray),
log: _setup("log", gray),
info: _setup("info", green),
warn: _setup("warn", yellow),
error: _setup("error", red),
};
// somewhere later in app
const clog = createClog("my-module");
clog("foo"); // output "[my-module] foo" in gray
clog.info("success"); // output "[my-module] success" in green
clog.error("alert!"); // output "[my-module] alert!" in red2.2.1
11 months ago
2.2.3
10 months ago
2.2.2
10 months ago
1.1.0
1 year ago
1.0.1
2 years ago
1.0.0
3 years ago
0.6.0
3 years ago
0.5.0
3 years ago
0.4.0
3 years ago
0.3.4
3 years ago
0.3.3
3 years ago
0.3.2
3 years ago
0.3.1
3 years ago
0.3.0
3 years ago
0.2.1
3 years ago
0.2.0
3 years ago
0.1.9
3 years ago
0.1.8
3 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.2
3 years ago