0.7.8 โ€ข Published 4 years ago

@xom9ik/logger v0.7.8

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

@xom9ik/logger

Logger with scopes logger preview

โœจ Features

  • ๐Ÿงจ possibility of changing scopes;
  • ๐Ÿ’Ž many palettes with amazing colors;
  • ๐Ÿ’ฃ fully customizable;
  • ๐Ÿ“Ž simple API;

๐Ÿงฒ Install

๐Ÿ“ฆ Via NPM

npm install @xom9ik/logger --save

๐Ÿงถ Via Yarn

yarn add @xom9ik/logger

๐Ÿ”ฅ Usage

๐Ÿ’ช Basic logger

const logger = require('@xom9ik/logger');

logger.server.info('Server has been started');
logger.database.trace('MongoDB connection established');
logger.client.error('Connection to wss://server.com/ refused');
logger.client.debug(`User data for ${id}:`, data);

โš™๏ธ Custom logger

It is possible to set your scopes and levels, the choice of custom colors. To do this, pass 3 optional parameters to the setup method. loggerConfig,activeLogs, options

const logger = require('@xom9ik/logger');

logger.setup(loggerConfig, [activeLogs, options]);

Setup params

loggerConfig

Represents an object, with fields, which is an object for representing a scope. The field scope includes color andlevels. color - is the color for the scope. levels - an object for representing levels, where the value is the color for the level.

activeLogs

Represents an object, with scope fields and an array for levels (if any). When configuring a logger without levels, the value true is used.

options

  • reverseOrder - Changes the output order for scope and level. The default is false.
  • timestamp - Time display in the format 1970/00/00 01:01:01.001. The default is true.
  • spaceSymbol - A symbol that separates scope and level. The default is space.

๐Ÿ’ก Info

Basic Scopes

  • server
  • client
  • database

Basic Levels

  • error
  • warning
  • info
  • trace
  • debug

Basic Palettes

palettes preview

  • flat
  • american
  • aussie
  • british
  • canadian
  • chinese
  • dutch
  • french
  • german

To get an object with all the palettes, you can call the getPalettes method

๐Ÿงญ Examples

loggerConfig

const loggerConfig = {
  server: {
    color: palettes.flat.turquoise,
  },
  mongodb: {
    color: palettes.flat.emerald,
    levels: {
      info: palettes.flat.peterRiver,
      warning: palettes.flat.amethyst,
      error: palettes.flat.wetAsphalt,
    },
  },
  grpc: {
    color: palettes.flat.greenSea,
    levels: {
      data: palettes.flat.nephritis,
      systemInfo: palettes.flat.belizeHole,
    },
  },
  beautifulScope: {
    color: palettes.flat.wisteria,
    levels: {
      yourCustomLogLevel: "#f7ea98",
      second: palettes.flat.mightBlue,
      third: "#9e4267",
      fourth: "#736408",
    },
  },
};

activeLogs

const activeLogs = {
    server: true,
    client: ['info', 'warning', 'error'],
    database: ['warning'],
    beautifulScope: ['yourCustomLogLevel', 'fourth'],
};

options

const options = {
    reverseOrder: false,
    timestamp: true,
    spaceSymbol: ' - ',
};

Output

logger.beautifulScope.yourCustomLogLevel('Please, output this log message');
// 1970/00/00 01:01:01.001 [BEAUTIFULSCOPE] - [YOURCUSTOMLOGLEVEL] Please, output this log message

logger.server('This scope has no levels');
// 1970/00/00 01:01:01.001 [SERVER] This scope has no levels

logger.beautifulScope.second('This level is not activated, messages will not be displayed');

Thanks to:

0.7.8

4 years ago

0.7.7

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago