2.1.0 • Published 5 months ago

nocol v2.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

nocl

Styled nodejs console logger

Installation

npm i nocol

Usage

import nocl, { Nocl } from "nocol";

nocl.log("Hello world!");

Default export: nocl - an instance of Nocl class

Create new instance

const nocl2 = new Nocl(options);
nocl2.log("Hello world from nocl2!");

Class init options / properties

You can also modify the properties directly to change the styling without creating new instance

nametypedefaultdescription
symbolPrefixobjectSymbol to be prepend to theme's symbol
symbolPostfixobjectSymbol to be append to theme's symbol
encloseSymbolbooleantrueEnclose symbol with square brackets
useChalkTemplatebooleanfalseColor text with chalk template
themeobjectDefaultThemeLogging theme style object

Default theme

namecolorsymbolsymbolColor
log#b6b5b5#b6b5b5
info#105ae4i#105ae4
error#ea4141x#ea4141
success#2cc22c#2cc22c
warning#e7a414!#e7a414
ts#b6b5b5{curr_timestamp}#636363
plusgreen+green
minusred-red
commentgray#gray

For color or symbolColor value, you can pass hex color or chalk ForegroundColor

themes

Examples

Modifying theme

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

modified_info_theme

Modifying theme: ts

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

modified_ts_theme

Using symbolPrefix

nocl.log("without symbolPrefix");
nocl.symbolPrefix = {
  symbol: "1/10",
};
nocl.log("with symbolPrefix");

symbolPrefix

Using symbolPostfix

nocl.log("without symbolPostfix");
nocl.symbolPostfix = {
  symbol: "username",
};
nocl.log("with symbolPostfix");

symbolPostfix

Using encloseSymbol

nocl.info("with encloseSymbol");
nocl.encloseSymbolColor = "blue";
nocl.info("with encloseSymbolColor");
nocl.encloseSymbolColor = null;
nocl.encloseSymbol = false;
nocl.info("without encloseSymbol");

encloseSymbol

Using useChalkTemplate

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

useChalkTemplate

.line

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

.group

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

Using session log

nocl.startSession(filepath, options); // createWriteStream
nocl.log("hello");
nocl.endSession();

sessionLogs


Check tests

TODO

  • session logging

Changelog

  • 2.1.0
    • added line method
    • customization improvements
  • 2.0.0
    • added clone, group, groupEnd, and nl methods
    • fixed theme setter typings
    • now using stdout for session logging
    • improvements
  • 1.1.4
    • fixed circular json error on session log
  • 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
1.1.4

6 months ago

2.1.0

5 months ago

2.0.0

6 months ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago