2.1.2 • Published 6 years ago

simple-fancy-log v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Demo

Demonstration of simple-fancy-log


What is simple-fancy-log?

This module helps creating clear, colorful, tagged logs

Logs are often ugly because not enough effort is put into making them clear and easy to read:

New user connected: 'Username'
User disconnected: 'Username'
Account created: 'Username#2'

And so on...

With simple-fancy-log

Comparative demonstration of simple-fancy-log into action


How to use

simple-fancy-log uses a main class: the SimpleFancyLog class. The module exports the class, so you have to create your own instance:

This is what you will have to write in order to obtain the same log as above (comparative log between )

const SimpleFancyLog = require("simple-fancy-log");

const logger = new SimpleFancyLog();

// To write the first line
logger.addTag({color: "green", content: "Connection"});
logger.log("User connected: 'Username'");

// To write the second line
logger.addTag({color: "red", content: "Disconnection"});
logger.log("User disconnected: 'Username'");

// To write the third line
logger.addTags(
  {bgColor: "magenta", color: "yellow", content: "New account"},
  {color: "green", content: "Connection"}
);
logger.log("Account created: 'Username#2'");

Alternatively, since the 2.1.0, you can use the following example to obtain the same result

const SimpleFancyLog = require("simple-fancy-log");
const logger = new SimpleFancyLog();

// Creating re-usable tags
SimpleFancyLog.createTag({name: "connection", content: "Connection", color: "green"});
SimpleFancyLog.createTag({name: "disconnection", content: "Disconnection", color: "red"});
SimpleFancyLog.createTag({name: "account-creation", content: "New account", color: "yellow", bgColor: "magenta"});

// To write the first line
logger.addTag("connection");
logger.log("User connected: 'Username'");

// To write the second line
logger.addTag("disconnection");
logger.log("User disconnected: 'Username'");

// To write the third line
logger.addTags("account-creation", "connection");
logger.log("Account created: 'Username#2'");

Reference

None of the methods are static, you always need an instance of the SimpleFancyLog class to call them

addTag(tag)

Function that adds a tag to the current line

Kind: Method of SimpleFancyLog

ParamTypeDefaultDescription
tagObjectObject that represents the tag to add
tag.contentStringContent of the tag ("test" yields "test")
tag.colorString"default"Foreground color of the tag
tag.bgColorString"default"Background color of the tag

addTags(tags)

Function that adds one or multiple _tags to the current line

Kind: Method of SimpleFancyLog

ParamTypeDefaultDescription
tagsObject | Array.<Object>Object(s) that represents the tag(s) to add
tags.contentStringContent of the tag ("test" yields "test")
tags.colorString"default"Foreground color of the tag
tags.bgColorString"default"Background color of the tag

removeTag(tag)

Function that adds a tag to the current line

Kind: Method of SimpleFancyLog

ParamTypeDefaultDescription
tagObjectObject that represents the tag to add
tag.contentStringContent of the tag ("test" yields "test")
tag.colorString""Foreground color of the tag
tag.bgColorString""Background color of the tag

removeTags(tags)

Function that removes one or multiple _tags from the current line

Kind: method of SimpleFancyLog

ParamTypeDefaultDescription
tagsObject | Array.<Object>Object(s) that represents the tag(s) to remove
tags.contentStringContent of the tag ("test" yields "test")
tags.colorString"default"Foreground color of the tag
tags.bgColorString"default"Background color of the tag

toString() ⇒ String

Function that returns the string that will be logged when the log function is called

Kind: Method of SimpleFancyLog
Returns: String - - String that will be logged when the log function is called

log(message)

Function that logs a message with all the set tags. This function resets the message and the tags after it is displayed

Kind: Method of SimpleFancyLog

ParamTypeDescription
messageStringMessage to display along with the tags

findTag(toFind) ⇒ *

Function that looks for a given tag

Kind: Static method of SimpleFancyLog
Returns: * - - Either {} or the tag object

ParamTypeDefaultDescription
toFindObjectOptions to find the tag
toFind.typeString""Type of the tag to find (primarily for base predefined tags)
toFind.nameString""Name of the tag to find (for user defined tags)

createTag(newTag) ⇒ *

Function that creates and stores a tag

Kind: Static method of SimpleFancyLog Returns: * - - Either {} (in case of an error) or the newly created tag object

ParamTypeDefaultDescription
newTagObjectTag to create
newTag.nameStringName of the tag to create
newTag.contentStringContent of the tag
newTag.typeString"default"Type (classifier) of the tag
newTag.colorString""Color of the tag
newTag.bgColorString""Background color of the tag

Available colors

The available colors are:

ColorForeground (text color)Background
default (terminal default)YesYes
redYesYes
yellowYesYes
greenYesYes
blueYesYes
cyanYesYes
whiteYesYes
black-Yes
magenta-Yes
2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

1.0.0

6 years ago