项目作者: idanavr

项目描述 :
Combine a few loggers into one.
高级语言: JavaScript
项目地址: git://github.com/idanavr/log-to-all.git
创建时间: 2020-06-01T11:57:52Z
项目社区:https://github.com/idanavr/log-to-all

开源协议:

下载


Log-To-All

NPM Version
CircleCI Status

Installation

  1. npm install log-to-all

or

  1. yarn add log-to-all

Try it out to see how simple it is

Sample project for using the package

Basic example

This example use two of the implemented loggers:

  1. const ConsoleLogger = require('log-to-all/lib/defaultLoggers/console');
  2. const FileLogger = require('log-to-all/lib/defaultLoggers/file');
  3. const logger = require('log-to-all').init([
  4. new ConsoleLogger(),
  5. new FileLogger(`${__dirname}/logs`)
  6. ]);
  7. logger.info('♫♪♫♪!');
  8. logger.debug('Will not be logged.');
  9. logger.setDebugMode(true);
  10. logger.debug('Now it will be logged.');

Implemented Loggers

Name Description
console Write the logs to the console
file Write the logs to files in the given path
  1. const ConsoleLogger = require('log-to-all/lib/defaultLoggers/console');
  2. const FileLogger = require('log-to-all/lib/defaultLoggers/file');

Add your own logger

In order to add your own logger all you have to do is to create new class with the functions:

  • debug(msg, params) - Will log only if debug mode set to true.
  • info(msg, params)
  • warn(msg, params)
  • error(msg, params)

It is recommended to use our base logger in order to make sure everything is implemented:

  1. const baseLogger = require("log-to-all/lib/logger");
  2. class YourLogger extends baseLogger {
  3. }

Then add it to the array of init function like this:

  1. const YourLogger = require('./YourLoggerPath');
  2. require('log-to-all').init([
  3. new YourLogger()
  4. ]);