# tree-logger

> tree-logger

Latest version **1.0.3** (published 2021-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install tree-logger
pnpm add tree-logger
yarn add tree-logger
bun add tree-logger
```

## 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.3 |
| Published | 2021-03-08 |
| First published | 2021-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | david-wu |
| Maintainers | david-wu |
| Keywords | tree, logger |

## Links

- npm: https://www.npmjs.com/package/tree-logger
- Repository: https://github.com/david-wu/tree-logger
- Homepage: https://github.com/david-wu/tree-logger#readme
- Issues: https://github.com/david-wu/tree-logger/issues
- npm.io page: https://npm.io/package/tree-logger

## 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.3 (latest) — 2021-03-08
- 1.0.2 — 2021-03-08
- 1.0.1 — 2021-03-08

## README

# tree-logger
Console logs trees.  It can be useful when debugging in terminal.


### Usage
```
const treeLogger = require('tree-logger');

const root = {
  value: 2,
  children: [
    {
      value: 3,
      children: [
        { value: 5 },
        { value: 6 },
      ],
    },
    {
      value: 4,
      children: [
        { value: 8 },
        { value: 10 },
      ],
    },
  ]
};
const log = treeLogger(root, (node) => node.children, (node) => node.value);
console.log(log);
```

```
└── 2
    ├── 3
    |   ├── 5
    |   └── 6
    └── 4
        ├── 8
        └── 10
```

### Advanced Usage
The second argument is a function that returns a node's children.
The third argument is a function that returns the node's label string.
This lets you log out nested structures that are not conventional trees.

```
const arrTree = [0, [1, 2, {}, [3, 4, 'cat'], 5, undefined], 6, null, [7, 8]];
const arrLog = treeLogger(
  arrTree,
  (d) => Array.isArray(d) ? d : [],
  (d) => Array.isArray(d) ? '[]' : d,
);
console.log(arrLog);
```

```
└── []
    ├── 0
    ├── []
    |   ├── 1
    |   ├── 2
    |   ├── [object Object]
    |   ├── []
    |   |   ├── 3
    |   |   ├── 4
    |   |   └── cat
    |   ├── 5
    |   ├── undefined
    ├── 6
    ├── null
    └── []
        ├── 7
        └── 8
```

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