npm install log-to-all
or
yarn add log-to-all
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.');
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');
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()
]);