Mirasaki / logger

My first NPM package with logging functions I use in most of my personal projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logger

Require the package

const logger = require('@mirasaki/logger');

Example Usage

logger.syslog('Start initializing...');
logger.syserr('Encountered error while trying to connect to database');
logger.success(`Client initialized after ${logger.getExecutionTime(process.hrtime())}`);
logger.info('Fetching data from API...');
logger.debug(`Execution time: ${logger.getExecutionTime(process.hrtime())}`);
logger.startLog('Application Command Data');
console.table(
  [
    {
      name: 'help',
      description: 'Display general information'
    },
    {
      name: 'start',
      description: 'Start task'
    }
  ]
);
logger.endLog('Application Command Data');

Outputs:

Example error logging

// catch (err) {} or .catch((err) => {})
logger.syserr(`An error has occurred while executing the /zz command`);
logger.printErr(err);

Outputs:

Functions

  • syslog
  • syserr
  • success
  • info
  • debug
  • database
  • startLog & endLog
  • timestamp: Returns the formatted timestamp for consistency
  • getExecutionTime: Pass process.hrtime() to get precise, formatted timeSince output
  • printErr: print an error object to the console in color

About

My first NPM package with logging functions I use in most of my personal projects.


Languages

Language:JavaScript 100.0%