Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lukasbach/table-log

CLI logging utility that logs lines as vertically aligned tabular data
https://github.com/lukasbach/table-log

cli ink log logging table tabular typed typescript

Last synced: 13 days ago
JSON representation

CLI logging utility that logs lines as vertically aligned tabular data

Awesome Lists containing this project

README

        

# `table-log`

> NPM utility tool to log lines as vertically aligned tabular data.

![Demo](demo/demo-no-border.gif)

## Get Started

Install the tool via `yarn add table-log` or `npm i table-log --save`. Then import
the utility via

```typescript
import { CliTable } from 'table-log';
```

Then, initialize a new table with `table = CliTable.createNoBorderTable()`,
and invoke `table.log(...lines)` to log a new line. The table is automatically adjusted
whenever a new longest cell is logged.

Complete example:

```typescript
import { CliTable } from 'table-log';

const table = CliTable.createNoBorderTable({
// Optional column alignments
colAligns: ['left', 'right', 'left', 'right'],

// Optional maximum column widths
colWidths: [undefined, undefined, 35, undefined]
});

table.log('Received', 'GET', '/users/obi-wan-kenobi', '(352ms)');
table.log('Received', 'GET', '/users/vader', '(241ms)');
table.log('Received', 'POST', '/lightsabers/red/vader', '(890ms)');
table.log('Received', 'POST', '/lightsabers/blue/obi-wan-kenobi', '(937ms)');
table.log('Received', 'OPTIONS', '/lightsabers/new', '(125ms)');
table.log('Received', 'PUT', '/lightsabers/new', '(11,335ms)');
table.log('Received', 'GET', '/users/yoda', '(452ms)');
table.log('Received', 'POST', '/lightsabers/green/yoda', '(676ms)');

// There may also pass some time between renders
await new Promise(r => setTimeout(r, 2000));

table.log('Received', 'GET', '/lightsabers/green/yoda/handle/material', '(124ms)');

table.unmount();

console.log("Table unmounted!");
```

You can also create a table with a border, by invoking `CliTable.createSingleBorderTable()`
or `CliTable.createDoubleBorderTable()` instead of `CliTable.createNoBorderTable()`.

![Demo](demo/demo-single-border.gif)
![Demo](demo/demo-double-border.gif)