styled nodejs console logger
npm install nocol
npm i nocol
`
Usage
`js
import nocl, { Nocl } from "nocol";
nocl.log("Hello world!");
`
Default export: nocl - an instance of _Nocl_ class
$3
`js
const nocl2 = new Nocl(options);
nocl2.log("Hello world from nocl2!");
`
$3
You can also modify the properties directly to change the styling without creating new instance
| name | type | default | description |
| ---------------- | ------- | ------------ | -------------------------------------- |
| symbolPrefix | object | | Symbol to be prepend to theme's symbol |
| symbolPostfix | object | | Symbol to be append to theme's symbol |
| encloseSymbol | boolean | true | Enclose symbol with square brackets |
| useChalkTemplate | boolean | false | Color text with chalk template |
| theme | object | DefaultTheme | Logging theme style object |
Default theme
| name | color | symbol | symbolColor |
| ------- | ------- | ---------------- | ----------- |
| log | #b6b5b5 | | #b6b5b5 |
| info | #105ae4 | i | #105ae4 |
| error | #ea4141 | x | #ea4141 |
| success | #2cc22c | ✓ | #2cc22c |
| warning | #e7a414 | ! | #e7a414 |
| ts | #b6b5b5 | {curr_timestamp} | #636363 |
| plus | green | + | green |
| minus | red | - | red |
| comment | gray | # | gray |
_For color or symbolColor value, you can pass hex color or chalk ForegroundColor_
!themes
Examples
$3
This will merge into current instance theme
`js
nocl.info("default theme");
const theme = {
info: {
symbol: "info",
symbolColor: "#074880",
},
};
nocl.theme = theme;
nocl.info("modified theme");
// OR
const nocl3 = new Nocl({
theme,
});
nocl3.info("modified theme from nocl3");
`
!modified_info_theme
$3
Change timestamp display
`js
nocl.ts("default theme: ts");
nocl.theme = {
ts: {
// type LocalesArgument
locales: undefined,
// type DateTimeFormatOptions
options: {
hour12: true,
timeStyle: "medium",
},
},
};
nocl.ts("modified theme: ts");
`
!modified_ts_theme
$3
`js
nocl.log("without symbolPrefix");
nocl.symbolPrefix = {
symbol: "1/10",
};
nocl.log("with symbolPrefix");
`
!symbolPrefix
$3
`js
nocl.log("without symbolPostfix");
nocl.symbolPostfix = {
symbol: "username",
};
nocl.log("with symbolPostfix");
`
!symbolPostfix
$3
`js
nocl.info("with encloseSymbol");
nocl.encloseSymbolColor = "blue";
nocl.info("with encloseSymbolColor");
nocl.encloseSymbolColor = null;
nocl.encloseSymbol = false;
nocl.info("without encloseSymbol");
`
!encloseSymbol
$3
This will fallback to chalk if there was an error coloring using template
`js
nocl.log("{yellow without using chalk template}");
nocl.useChalkTemplate = true;
nocl.log("{yellow using chalk template}");
`
!useChalkTemplate
$3
`js
nocl.line();
nocl.line({ color: "magenta", symbol: "~" });
nocl.line({ label: "Left" });
nocl.line({ label: "{white.inverse Center }", align: "center" });
nocl.line({ color: "green", symbol: "~", label: "Right", align: "right" });
nocl.line({ symbol: " ", label: "{white.inverse Center }", align: "center" });
nocl.line({ symbol: " ", label: "{white.inverse Left }", align: "left" });
nocl.line({ symbol: " ", label: "{white.inverse Right }", align: "right" });
`
!line
$3
`js
const n = new Nocl({ useChalkTemplate: true });
n.group("ms:");
n.log("a");
n.group("{yellow members3:}");
n.log("b");
n.groupEnd();
n.log("c");
n.groupEnd();
n.log("d");
`
!group
$3
`js
nocl.startSession(filepath, options); // createWriteStream
nocl.log("hello");
nocl.endSession();
``