Styled nodejs console logger
npm i nocol
import nocl, { Nocl } from "nocol";
nocl.log("Hello world!");
Default export: nocl
- an instance of Nocl class
const nocl2 = new Nocl(options);
nocl2.log("Hello world from nocl2!");
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 |
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
This will merge into current instance theme
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");
Change timestamp display
nocl.ts("default theme: ts");
nocl.theme = {
ts: {
// type LocalesArgument
locales: undefined,
// type DateTimeFormatOptions
options: {
hour12: true,
timeStyle: "medium",
},
},
};
nocl.ts("modified theme: ts");
nocl.log("without symbolPrefix");
nocl.symbolPrefix = {
symbol: "1/10",
};
nocl.log("with symbolPrefix");
nocl.log("without symbolPostfix");
nocl.symbolPostfix = {
symbol: "username",
};
nocl.log("with symbolPostfix");
nocl.info("with encloseSymbol");
nocl.encloseSymbol = false;
nocl.info("without encloseSymbol");
This will fallback to chalk if there was an error coloring using template
nocl.log("{yellow without using chalk template}");
nocl.useChalkTemplate = true;
nocl.log("{yellow using chalk template}");
nocl.startSession(filepath, options); // createWriteStream
nocl.log("hello");
nocl.endSession();
Check tests
- session logging
- 1.1.3
- fixed chalk template
- 1.1.2
- added new theme "comment"
- 1.1.1
- added object support for session log
- 1.1.0
- added session logging
- 1.0.2
- stable version