Skip to content

baahkusi/logoligi

Repository files navigation

logoligi

Ties chalk, boxen & ora behind a simple logging api. Wrapps around console.log. This allows you to do the following;

Install

npm i logoligi

Usage

import Logger from 'logoligi';

// start logging 
Logger.log('Hi');

// log with config
Logger.log('Hello', {
   color: 'blue', // https://github.com/chalk/chalk/tree/main#colors
   bgColor: 'white', // https://github.com/chalk/chalk/tree/main#background-colors
   box: 'double' // https://github.com/sindresorhus/boxen/tree/main#borderstyle
});

// full config interface
/*
interface LoggerConfigI {
  color?: string;
  bgColor?: string;
  box?: string;
  title?: string;
  status?: "warn" | "success" | "fail" | "info" | "end"; // only for Logger.endLog ...
}
*/

// default configs for different log levels have been set
Logger.info('H');
Logger.debug('E');
Logger.warn('LL');
Logger.error('O');

// you can pass config for each of these
Logger.info('Okay!', {
   color: 'yello'
});

// show loader whilst asyn process is running
const logger = Logger.startLog('Downloading ...');
await new Promise(r => setTimeout(r, 2000));
Logger.endLog(logger, 'Finished Downloading!');
Logger.endLog(logger, 'Finished Downloading!', { status: 'success' }); // indicate success check mark in console
// indicate failure
Logger.endLog(logger, 'failed Downloading!', { status: 'fail' }); 
// you can indicate error, info, and warning as well.