@xom9ik/logger

0.7.8 • Public • Published

@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 and levels. 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:

Package Sidebar

Install

npm i @xom9ik/logger

Weekly Downloads

1

Version

0.7.8

License

MIT

Unpacked Size

17.8 kB

Total Files

7

Last publish

Collaborators

  • npm
  • xom9ik