1.6.4 • Published 1 year ago

@tgsnake/log v1.6.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Tgsnake Log

This framework is used to better display logs on your console or terminal.

Available log levels

This framework using env in node and localStorage in browser for betters performance :

  • LOGLEVEL : To save the log level. So only declaring in one instance, all instance can read that log level.
  • LOGFILTERS : To save any instance that can display context on console or terminal (according to the name that was given at the time of initialization). default is all,unamed.
  • LOGWARNINGLEVEL : To save the warning level.

  • debug or verbose : To showing all level in terminal.

  • info : Shows only context with level info on console or terminal.
  • error : Shows only context with level error on console or terminal.
  • warn : Shows only context with level warn (warning) on console or terminal.
  • none : Will not display anything on console or terminal

How to use

const { Logger } = require('@tgsnake/log');
const log = new Logger({
  name: 'some-string-without-space-here',
  level: ['debug'], // default level for this log
});

log.log('Hello World'); // (name) info - Hello World DD/MM/YY hh:mm:ss.ms

Class Method

  • log : Print log without template.
  • info : Print log as info level.
  • error : Print log as error level.
  • warning : Print log as warning level.
  • combine : Print log as multiple level.
  • debug : Print log as debug level.
  • setLogLevel : Setting the log level.
  • setWarningLevel : Setting the warning level. hard if you want show the context in all log level, soft if you want show the context only in warning or debug or verbose level.
  • setFilters : Setting any instance that can display context in the console or terminal.

Options

parametertypedescription
namestringName of logger instance, default is unamed
levelArray of debug, none, info, error, verboseThe level of the logger. By default it will take the value from the env LOGLEVEL or if it is not available it will automatically go into debug level
customColorColorConsole color customization

Color

On deno supports chalk v5 customization while on node supports chalk v4 customization. For RGB, HSL (only for node), HSV (only for node), HWB (only for node), you can use the format: format(a,b,c) example rgb(0,0,0) or hsl(0,0,0). And you can directly provide the hex code (eg: #fff). In nodes, you can also use keywords from CSS like orange.

categorytypedescription
namestringcolor of logger name
datestringcolor of date
debugstringcolor when debug level and verbose level
infostringcolor when info level
errorstringcolor when error level
warningstringcolor when warning level

Example

const { Logger } = require("@tgsnake/log")
const log = new Logger({
  name : "some-string-without-space-here",
  level : ["debug"] // default level for this log,
  customColor : {
    debug: 'blue',
    info: 'rgb(0,255,0)',
    error: '#ff0505',
    warning: 'hsv(44,98,100)',
    name: 'azure',
    date: 'grey',
  }
})

MIT LICENSE

Build with ♥️ by tgsnake dev.

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.2.0

3 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago