# pretty-json-log

> Convert JSON log lines into simple pretty colored log output

Latest version **1.5.0** (published 2024-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install pretty-json-log
pnpm add pretty-json-log
yarn add pretty-json-log
bun add pretty-json-log
```

Provides the command `pjl`.

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2024-01-03 |
| First published | 2019-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 41.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Blayne Chard |
| Maintainers | blacha |

## Links

- npm: https://www.npmjs.com/package/pretty-json-log
- Repository: https://github.com/blacha/pretty-json-log
- Homepage: https://github.com/blacha/pretty-json-log#readme
- Issues: https://github.com/blacha/pretty-json-log/issues
- npm.io page: https://npm.io/package/pretty-json-log

## Dependencies (2)

- [split2](https://npm.io/package/split2.md) ^4.2.0
- [ansi-colors](https://npm.io/package/ansi-colors.md) ^4.1.1

## Recent versions

- 1.5.0 (latest) — 2024-01-03
- 1.4.0 — 2023-04-27
- 1.3.0 — 2022-09-14
- 1.2.0 — 2022-08-30
- 1.1.2 — 2022-08-08
- 1.1.1 — 2022-08-08
- 1.1.0 — 2022-08-08
- 1.0.0 — 2021-09-11
- 0.3.5 — 2021-09-07
- 0.3.4 — 2021-09-07
- 0.3.3 — 2021-09-07
- 0.3.2 — 2020-11-23
- 0.3.1 — 2020-05-12
- 0.2.2 — 2020-01-17
- 0.2.0 — 2020-01-17
- … 8 more at https://npm.io/package/pretty-json-log/versions

## README

# Pretty Json Log (PJL)

Convert JSON log lines into simple pretty colored log output

Converts

```json
{"pid":0,"time":"2019-11-03T00:48:55.623Z","hostname":"","level":30,"msg":"HTTPGet","v":0,"name":"cogview","firstChunk":0,"lastChunk":0,"chunkCount":1,"bytes":32768,"fetchRange":"bytes=0-32768"}
{"pid":0,"time":"2019-11-03T00:48:55.677Z","hostname":"","level":30,"msg":"HTTPGet","v":0,"name":"cogview","firstChunk":94,"lastChunk":95,"chunkCount":1,"bytes":32768,"fetchRange":"bytes=3080192-3145728"}
```

into

![Example output](./static/pretty-output.png)

![Example output OpenTelemetry](./static/pretty-output-ot.png)

## Install

```bash
npm i -g pretty-json-log

cat <log-file> | pjl 
```

Logs can be filtered using `--level`

```
cat <log-file> | pjl --level 20
```

### OpenTelemetry Log options

Do not output `Resources` 

```
cat <log-file> | pjl --ignore-resources
```

## Basic log type

To be pretty printable the basic json line needs to have:

Either:

1. A PinoJS log message

```typescript
/** Base log object every log object should have at minimum these three keys */
export interface LogMessage extends Record<string, any> {
    /** Log level */
    level: number;
    /** Time stamp either a ISO8601 string, timestamp number in ms or a Date */
    time: number | string | Date;
    /** Log message */
    msg: string;
}
```

2. A [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md) Log Message

```typescript
export interface LogMessageOpenTelemetry {
    /** Timestamp in nanoseconds if a string, or ms if a number */
    Timestamp: number | string
    /** Message body */
    Body?: unknown;
    Resource?: Record<string, unknown>;
    Attributes?: Record<string, unknown>;
}
```

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