Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vajahath/log-to-json
Yet another transform stream NPM module to convert `.log` files to `.json`.
https://github.com/vajahath/log-to-json
Last synced: about 13 hours ago
JSON representation
Yet another transform stream NPM module to convert `.log` files to `.json`.
- Host: GitHub
- URL: https://github.com/vajahath/log-to-json
- Owner: vajahath
- License: mit
- Created: 2020-02-19T16:02:08.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T07:45:10.000Z (about 2 years ago)
- Last Synced: 2025-01-12T09:39:49.881Z (7 days ago)
- Language: TypeScript
- Size: 1.37 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# log-to-json
Yet another transform stream to convert JSON like `.log` files to `.json`.
![](https://github.com/vajahath/log-to-json/workflows/Build/badge.svg) [![](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
If you are looking for the CLI, see [log-to-json-cli](https://github.com/vajahath/log-to-json-cli).
## Install
Requires Node >=10.
From npm,
```sh
npm i log-to-json
```From [Github Package Registry](https://github.com/vajahath/log-to-json/packages). ([Guide](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages)).
Type definitions are bundled with this package.
## Usage
This module uses streams, so you can handle large files.
```ts
const { LogToJSON } = require('log-to-json');
// or
import { LogToJSON } from 'log-to-json';const converter = new LogToJSON();
fs.createReadStream('my.log')
.pipe(converter)
.pipe(fs.createWriteStream('my.log.json'));
````my.log`:
```log
{"my": 5, "log":9, "file": "fsadf"} # each object is a one-liner (this is necessary)
{"my": 5, "log":9, "file": "fsadf"}
{"my": 5, "log":9, "file": "fsadf"}
{"my": 5, "log":9, "file": "fsadf"}
````my.log.json`:
```json
[
{ "my": 5, "log": 9, "file": "fsadf" },
{ "my": 5, "log": 9, "file": "fsadf" },
{ "my": 5, "log": 9, "file": "fsadf" },
{ "my": 5, "log": 9, "file": "fsadf" }
]
```**Do not use this module if your your log files are not JSON like.**
[![](https://img.shields.io/badge/built%20with-ts--np%203-lightgrey?style=flat-square)](https://github.com/vajahath/generator-ts-np)
## Licence
MIT © [Vajahath Ahmed](https://twitter.com/vajahath7)