@vcsuite/cli-logger
v1.0.0
Published
A logger for all vcs CLI packages
Downloads
4,654
Readme
@vcsuite/cli-logger
A logger for all vcs CLI packages.
npm i @vcsuite/cli-logger
Log levels (in ascending order):
- "OFF"
- "ERROR"
- "WARN"
- "INFO"
- "VERBOSE"
- "DEBUG"
Example Usage
Set log level via command prompt:
const program = require('commander');
const { setLevel } = require('@vcsuite/cli-logger');
program
.version(version)
.option('--verbose [level]', 'the log level, one of "ERROR", "WARN", "INFO", "DEBUG"', setLevel, 'info')
Simple log messages:
const { logger } = require('@vcsuite/cli-logger');
// (level "ERROR")
logger.error('this is an error message');
// (level "WARN")
logger.warning('this is a warning');
// (level "INFO")
logger.log('this is a log message');
Styled log messages:
const { logger } = require('@vcsuite/cli-logger');
// printed blue (level "INFO")
logger.info('this is an info message');
// printed green (level "INFO")
logger.success('execution successful');
// printed red (level "ERROR")
logger.failure('execution failed');
Indicate progress using Spinner:
/**
* @param {string} id
* @return {Promise<void>}
*/
async function clean(id) {
const dir = path.join('directory');
logger.spin('cleaning directory');
if (fs.existsSync(dir)) {
await del([`./${id}/**/*`, `./${id}.json`], { cwd: dir });
}
logger.stopSpinner();
logger.success('directory is clean.');
}
Attention: You can still log while spinning. It is important to stop the spinner, otherwise the cli has an open socket and won't close.