/messaggio

Primary LanguageTypeScript

Messaggio


A console logger that produces beautiful and readable messages.

📝 Table of Contents

About

Messaggio was developed for logging purposes and status reporting in Node.js CLI-Applications.

Features

  • Six simple message types (debug, error, fatal, info, warning, success)
  • Possibility to ask yes/no questions
  • Timers
  • Timestamp and date support
  • Fully customizable (add new message types or change existing ones)
  • Two beautiful message output formats: line and box
  • Written in Typescript

Prerequisites

You need at least Node.js version 10.15.0 installed on your computer.

Installation

Open your command line, go to the root folder of your project which contains the package.json file and insert the following command to install the latest version of Messaggio.

npm install messaggio

Usage

Simple Messages

import { Messagio } from 'messagio';

const messaggio = new Messagio();

messaggio.debug('Debug Message');
messaggio.error('Error Message');
messaggio.fatal('Fatal Error Message');
messaggio.info('Info Message');
messaggio.success('Success Message');
messaggio.warning('Warning Message');

Yes/No Question

Promises Syntax

import { Messagio } from 'messagio';

const messaggio = new Messagio();

messaggio.questionYesNo('Do you really want to delete x?')
  .then((answer) => {
    // if answer is yes, the return value is true
    // if answer is no, the return value is false
  })
  .catch((error) => {
    // handle possible error
  });

Async/Await Syntax

import { Messagio } from 'messagio';

const messaggio = new Messagio();

const answer = await messaggio.questionYesNo('Do you really want to delete x?');

Timers

With explicit id

import { Messagio } from 'messagio';

const messaggio = new Messagio();

messaggio.startTimer('Transformation XYZ', 'transformation-xyz');
messaggio.success('XYZ has been transformed');
messaggio.stopTimer('transformation-xyz');

With id returned

The function startTimer() returns the id of the timer so you could also do the following:

import { Messagio } from 'messagio';

const messaggio = new Messagio();

const id = messaggio.startTimer('Transformation XYZ', 'transformation-xyz');
messaggio.success('XYZ has been transformed');
messaggio.stopTimer(id);

With id omitted

You can also omit the id-parameter from the function startTimer(). In this case Messaggio will automatically assign an id to the timer.

import { Messagio } from 'messagio';

const messaggio = new Messagio();

const id = messaggio.startTimer('Transformation XYZ');
messaggio.success('XYZ has been transformed');
messaggio.stopTimer(id);

Customizations

Add a scope to every message

Per default Messaggio doesn't add a scope to the messages it produces. However you can easily change that.

import { Messagio } from 'messagio';

const messaggio = new Messagio({
  'scope': 'my-app'
});

messaggio.info('Info Message');

Deactivate horizontal alignment of long messages

Per default Messaggio tries to horizontally align long messages in such a way that they become more readable. You can deactivate this functionality in the following way:

import { Messagio } from 'messagio';

const messaggio = new Messagio({
  'alignLongLinesHorizontally': false
});

messaggio.info('A very very very very very very very very very very very very very very very very very very long Info Message');

Change the message output format

Per default Messaggio outputs messagges line by line. However, you can also choose to display messages within boxes:

import { Messagio } from 'messagio';

const messaggio = new Messagio({
  'messageFormat': 'box'
});

messaggio.info('An Info Message');

Customize an existing message type

TODO

Add a new message type

TODO

Built Using

Author

Acknowledgements