1.0.0-beta.1 • Published 5 months ago

rellog v1.0.0-beta.1

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

rellog

Logger system for Relteco-Relnode

npm i rellog

Quick Start

const {RelLog,LOG_COLORS} = require("rellog")

const RL = new RelLog()
RL.LOG("this is a info log", "i")

OR

import {RelLog,LOG_COLORS} = from "rellog"

const RL = new RelLog()
RL.LOG("this is a info log", "i")

LOG_COLORS

Ansi color codes.

  • reset
  • black
  • red
  • green
  • yellow
  • blue
  • purple
  • cyan
  • white
  • bold_black
  • bold_red
  • bold_green
  • bold_yellow
  • bold_blue
  • bold_purple
  • bold_cyan
  • bold_white
  • bg_bold_black
  • bg_bold_red
  • bg_bold_green
  • bg_bold_yellow
  • bg_bold_blue
  • bg_bold_purple
  • bg_bold_cyan
  • bg_bold_white

RelLog

Advanced Synchronous File and Console Logging System for Relteco-Relnode.

You can capture log records to the main file and simultaneously to a custom file, and optionally print log outputs to the console as per your preference.

It also supports on-the-fly custom logging without the need for any main configuration when needed.


Options

OPTIONTYPEDEFAULTDESCRIPTION
FileNamestringrelnode.logMain log file name
FilePathstring./logsMain log file path
Optionsobject{T_Options}DefaultOptionsMain log options

Examples:

const {RelLog,LOG_COLORS} = require("rellog")

const RL = new RelLog()
const RL = new RelLog("./logs")
const RL = new RelLog("./logs","custom.log")
const RL = new RelLog("./logs","custom.log",{ConsoleMode:false,Colors:{titleColor:LOG_COLORS.bg_bold_green}})

OR

import {RelLog,LOG_COLORS} = from "rellog"

const RL = new RelLog()
const RL = new RelLog("./logs")
const RL = new RelLog("./logs","custom.log")
const RL = new RelLog("./logs","custom.log",{ConsoleMode:false,Colors:{titleColor:LOG_COLORS.bg_bold_green}})

Options

Main log options


T_Options Type Options

OPTIONTYPEDEFAULTDESCRIPTION
ConsoleModebooleantrueWhether the main log should be displayed on the console or not
FileModebooleantrueWhether the main log should be written to the main file or not
HighLigthModebooleanfalseWhether color codes should be included when writing the main log to the file
Colorsobject{T_Colors}DefaultColorsColor values for the main log

NOTE: When HighLightMode is true, the color of the logged messages is included in the log file. This may reduce readability for normal readers, but it ensures that the log output is well-organized and colorful when retrieved with console commands like 'cat'.

  • Type: object{T_Options}

  • Default: DefaultOptions

    \ \ \

    T_Colors Type Options

    It retrieves the colors from the LOG_COLORS object.


    OPTIONTYPEDEFAULTDESCRIPTION
    titleColorstringLOG_COLORS.bg_bold_yellowTitle color of main log
    dateColorstringLOG_COLORS.greenDate color of main log
    contextColorstringLOG_COLORS.whiteContext color of main log

FilePath

Main log file path


  • Type: string

  • Default: ./logs

FileName

Main log file name


  • Type: string

  • Default: relnode.log

METHODS

LOG()

It performs logging to the desired or main file while simultaneously printing log output to the console if requested.

Options

OPTIONTYPEDEFAULTDESCRIPTION
contextstring""Log context
typestringwLog type (w/W-e/E-i/I-d/D)
titlestring[RelLog]Log title
Optionsobject{T_Options}DefaultOptionsLog options
FileNamestringrelnode.logLog file name
FilePathstring./logsLog file path

Examples:

const {RelLog,LOG_COLORS} = require("rellog")

RL.LOG("this is a info log", "i")
RL.LOG("this is a error log  with log title [BERK]", "E", "BERK")


RL.LOG("Log displayed only in the console.", "w", "[BERK]", { FileMode: false})
RL.LOG("warning log displayed only in the console and Colored log with title", "w", "[BERK]", { FileMode: false, Colors: { titleColor: LOG_COLORS.bg_bold_green } })
RL.LOG("Active debug log in HighLigthMode.", "d", "[BERK]", { ConsoleMode: true, HighLigthMode: true, Colors: { titleColor: LOG_COLORS.bg_bold_green, dateColor: LOG_COLORS.blue } })

RL.LOG("log with custom file name", "w", "[BERK]", {},"custom.log")
RL.LOG("log with default file name and file path", "w", "[BERK]", {},"custom.log",RL.FilePath)
RL.LOG("log with custom file name and file path", "w", "[BERK]", {},"custom.log","./logs")

// Write log data for the `pre mode` within `` symbols
RL.LOG(`bla bla 
bla blablablabla 
bla 
blablablabla`, "E", "BERK")  

context

Log context

Type:string

default ""

type

Log type

The value names can be in either uppercase or lowercase.

type: string

default w

OPTIONTYPEDEFAULTDESCRIPTION
w | WstringwWARNING
e | EstringeERROR
i | IstringiINFO
d | DstringdDEBUG

title

Log title

Type:string

default [RelLog]

Options

Main log options


T_Options Type Options

  • OPTIONTYPEDEFAULTDESCRIPTION
    ConsoleModebooleantrueWhether the main log should be displayed on the console or not
    FileModebooleantrueWhether the main log should be written to the main file or not
    HighLigthModebooleanfalseWhether color codes should be included when writing the main log to the file
    Colorsobject{T_Colors}DefaultColorsColor values for the main log

NOTE: When HighLightMode is true, the color of the logged messages is included in the log file. This may reduce readability for normal readers, but it ensures that the log output is well-organized and colorful when retrieved with console commands like 'cat'.

Type: object{T_Options}

Default: DefaultOptions

\ \ \

T_Colors Type Options

It retrieves the colors from the LOG_COLORS object.


OPTIONTYPEDEFAULTDESCRIPTION
titleColorstringLOG_COLORS.bg_bold_yellowTitle color of main log
dateColorstringLOG_COLORS.greenDate color of main log
contextColorstringLOG_COLORS.whiteContext color of main log

FileName

Log file name

Type:string

default relnode.log

filePath

Log file path

Type:string

default ./logs

LOGTABLE()

It performs logging to the desired or main file while simultaneously printing log output to the console if requested.

Options

OPTIONTYPEDEFAULTDESCRIPTION
dataarrayany[]Table contexts
headarraystring[]Table headers

NOTE : If the LOGTABLE has an empty head, it will create a regular table. The head argument enables the table to be horizontal, leading to different expectations for the content of the data argument

Examples:

// An example of a regular table with the `head` argument:
// Currently, the `normaldata` argument accepts an array of objects

 const normaldata = [
   { 'Some key': 'Some value' },
   { 'Another key': 'Another value' }
 ];
  RL.LOGTABLE(normaldata)

\ \

// An example of a regular table without the `head` argument:
// Currently, the `headerdata` argument accepts an array of arrays

const headerdata = [
  ['First value', 'Second value'],
  ['First value', 'Second value']
];
// and headers 
const headers = ['TH 1 label', 'TH 2 label']

  RL.LOGTABLE(headerdata, headers)
1.0.0-beta.1

5 months ago