log-to-all

0.1.4 • Public • Published

Log-To-All

NPM Version CircleCI Status

Installation

npm install log-to-all

or

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:

const ConsoleLogger = require('log-to-all/lib/defaultLoggers/console');
const FileLogger = require('log-to-all/lib/defaultLoggers/file');
const logger = require('log-to-all').init([
  new ConsoleLogger(),
  new FileLogger(`${__dirname}/logs`)
]);
logger.info('♫♪♫♪!');

logger.debug('Will not be logged.');
logger.setDebugMode(true);
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

 

const ConsoleLogger = require('log-to-all/lib/defaultLoggers/console');
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:

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

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

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

Package Sidebar

Install

npm i log-to-all

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

8.17 kB

Total Files

7

Last publish

Collaborators

  • idanavr