# grid-log

> A logging utility that handles multi-line strings

Latest version **1.0.1** (published 2023-02-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install grid-log
pnpm add grid-log
yarn add grid-log
bun add grid-log
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-02-16 |
| First published | 2023-02-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Matt Kruse |
| Maintainers | mkruse |
| Keywords | log, multiline |

## Links

- npm: https://www.npmjs.com/package/grid-log
- Repository: https://github.com/matt-kruse/grid-log
- Homepage: https://github.com/matt-kruse/grid-log#readme
- Issues: https://github.com/matt-kruse/grid-log/issues
- npm.io page: https://npm.io/package/grid-log

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-02-16
- 1.0.0 — 2023-02-02

## README

# grid-log

A logging utility that handles multi-line strings.

`console.log()` does not display multi-line strings, nor does `console.table()`. This util lets you log strings in a grid format.

**Note:** The fonts used on npmjs.com do not render table characters correctly below. View examples at https://github.com/matt-kruse/grid-log#readme  

# Usage

#### 
```javascript
console.grid = require('grid-log');

const a = `This is\na multi-line\nstring`;
const b = {'this':'is','a':{'nested':'object'}};
const c = ['a','b','c','d','e','f'];
```

#### Example
```javascript
console.grid(a,b,c);
```

#### Output
```
┌──────────────┬────────────────────────┬────────┐
│ This is      │ {                      │ [      │
│ a multi-line │   "this": "is",        │   "a", │
│ string       │   "a": {               │   "b", │
│              │     "nested": "object" │   "c", │
│              │   }                    │   "d", │
│              │ }                      │   "e", │
│              │                        │   "f"  │
│              │                        │ ]      │
└──────────────┴────────────────────────┴────────┘
```

#### Example
```javascript
// Output multiple rows
// Number of columns don't need to match
console.grid.resetOptions();
console.grid([a],[b,c])
```

#### Output
```
┌────────────────────────┬────────┐
│ This is                │        │
│ a multi-line           │        │
│ string                 │        │
├────────────────────────┼────────┤
│ {                      │ [      │
│   "this": "is",        │   "a", │
│   "a": {               │   "b", │
│     "nested": "object" │   "c", │
│   }                    │   "d", │
│ }                      │   "e", │
│                        │   "f"  │
│                        │ ]      │
└────────────────────────┴────────┘
```

#### Example
```javascript
// Add a Header Row
console.grid(
    ['COLUMN 1','COLUMN 2','THIS IS A REALLY LONG COLUMN NAME'],
    [a,b],
    [,c]
);
```

#### Output
```
┌──────────────┬────────────────────────┬───────────────────────────────────┐
│ COLUMN 1     │ COLUMN 2               │ THIS IS A REALLY LONG COLUMN NAME │
├──────────────┼────────────────────────┼───────────────────────────────────┤
│ This is      │ {                      │                                   │
│ a multi-line │   "this": "is",        │                                   │
│ string       │   "a": {               │                                   │
│              │     "nested": "object" │                                   │
│              │   }                    │                                   │
│              │ }                      │                                   │
├──────────────┼────────────────────────┼───────────────────────────────────┤
│              │ [                      │                                   │
│              │   "a",                 │                                   │
│              │   "b",                 │                                   │
│              │   "c",                 │                                   │
│              │   "d",                 │                                   │
│              │   "e",                 │                                   │
│              │   "f"                  │                                   │
│              │ ]                      │                                   │
└──────────────┴────────────────────────┴───────────────────────────────────┘
```

#### Example
```javascript
// Change indent size for automatic JSON.stringify()
console.grid.options({jsonIndent: 4});
console.grid(a,b,c);
```

#### Output
```
┌──────────────┬────────────────────────────┬──────────┐
│ This is      │ {                          │ [        │
│ a multi-line │     "this": "is",          │     "a", │
│ string       │     "a": {                 │     "b", │
│              │         "nested": "object" │     "c", │
│              │     }                      │     "d", │
│              │ }                          │     "e", │
│              │                            │     "f"  │
│              │                            │ ]        │
└──────────────┴────────────────────────────┴──────────┘
```

#### Example
```javascript
// Left/Right padding on cells
console.grid.resetOptions().options({cellPadding: 4});
console.grid(a,b,c);
```

#### Output
```
┌────────────────────┬──────────────────────────────┬──────────────┐
│    This is         │    {                         │    [         │
│    a multi-line    │      "this": "is",           │      "a",    │
│    string          │      "a": {                  │      "b",    │
│                    │        "nested": "object"    │      "c",    │
│                    │      }                       │      "d",    │
│                    │    }                         │      "e",    │
│                    │                              │      "f"     │
│                    │                              │    ]         │
└────────────────────┴──────────────────────────────┴──────────────┘
```

#### Example
```javascript
// Use ascii grid characters
console.grid.resetOptions().options({ascii:true});
console.grid(a,b,c);
```

#### Output
```
+--------------+------------------------+--------+
| This is      | {                      | [      |
| a multi-line |   "this": "is",        |   "a", |
| string       |   "a": {               |   "b", |
|              |     "nested": "object" |   "c", |
|              |   }                    |   "d", |
|              | }                      |   "e", |
|              |                        |   "f"  |
|              |                        | ]      |
+--------------+------------------------+--------+
```

#### Example
```javascript
// Return a string instead of calling console.log()
console.grid.resetOptions().options({consoleLog:false});
let log = console.grid(a,b,c);
console.info("The output is:\n"+log);
```

#### Output
```
The output is:
┌──────────────┬────────────────────────┬────────┐
│ This is      │ {                      │ [      │
│ a multi-line │   "this": "is",        │   "a", │
│ string       │   "a": {               │   "b", │
│              │     "nested": "object" │   "c", │
│              │   }                    │   "d", │
│              │ }                      │   "e", │
│              │                        │   "f"  │
│              │                        │ ]      │
└──────────────┴────────────────────────┴────────┘
```

---
_Source: https://npm.io/package/grid-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
