Node.js readline based simple logging utility.
This logger is made to work with readline. It will preserve current text being inputted and not write on the same line as texting being written.
It does not show up rl.on('line') and works with rl prompt.
This is not meant to replace console.log with normal use. It is to be used while using readline.
Require the file to get the logger class :
const LoggerClass = require('./logger.js');
Make a new logger object :
const Logger = new LoggerClass();
You can then use the library :
const log = Logger.logger;
const rl = Logger.rl;
const readline = Logger.readline;
rl.on('line', (text) => {
log(`Got this input ${text}`);
});
log.color('Program started!', 'green');
(No pass rl)
const log = (new ( require('./logger.js') )()).logger;
const rl = log.rl;
const readline = log.readline;
log('Hello!');
(Pass rl)
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const log = (new ( require('./logger.js') )(rl)).logger;
log('Hello!');
const LoggerClass = require('./logger.js');
const Logger = new LoggerClass(args);
If args
is blank then the Logger will create a readline instance.
If args
is a non readline interface object it will pass that object as a parameter to readline.createInterface
.
If args
is a readline interface the Logger will use that.
log(text)
log.warn(text, suppressStackTrace)
log.error(text, suppressStackTrace)
log.color(text, color)
reset
- Resets colors (used internally)
reset
black
red
green
yellow
blue
magenta
cyan
white