Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

log-to-csv

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log-to-csv

log-to-csv

  • 1.0.8
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

log-to-csv

Log files Parser that takes the log files (often txt files) and insert them into some kind of pipe with regex of your implementation and returns a CSV format-like. The pipe will receive Line-By-Line, and will proccess it throught the regex syntax, and will move to the next line until finishing the InputStream.

What to do?

Implement ILineParser interface [TypeScript Recommended]

  import { ILineParser } from 'log-to-csv';
  export class CustomParser implements ILineParser { }

Install

npm i --save log-to-csv

Developer section

npm run build

Basic Usage

import Log2Csv from 'log-to-csv';
import NotificationEventsParser from './Examples/NotificationEventsParser';

var app = new log2Csv(
    'input.txt',
    new NotificationEventsParser(),
    (output) => process.stdout.write(output)
);

app.parse();
import { ILineParser } from 'log-to-csv';

/**
 * NotificationEventsParser Implementation example to fetch the relevant data in logs for `AndroidNotification` method
 * @author Islam Attrash
 */
export default class NotificationEventsParser implements ILineParser {

    public regx:RegExp;
    public header:string;

    constructor() {
        //Recognize Notification States
        //Example: 2017-01-29 11:19:39.778 961-4981/? D/AndroidNotification: notifiy message:how are you?, packageName:com.ns.app1
        this.regx = /(\d+-\d+-\d+ \d+:\d+:\d+).+AndroidNotification: notifiy message:(.+),/;
        this.header = `Date,Timestamp,NotificationMessage\n`;
    }

    /**
     * Get line relevant values
     * @returns ${dateString},${timestamp},${notifyMessage}
     */
    getLineRegexValues(line) {
        let values =  this.regx.exec(line);
        if(values === null) {
            return null;
        } else {
            let dateString = values[1];
            let timestamp = new Date(dateString).getTime();
            let notifyMessage = values[2];
            return `${dateString},${timestamp},${notifyMessage}`;
        }
    }

}

Live Demo (Parser in Examples folder)

- Takes Android logs and fetch some kind of method called AndroidNotification and shows the notification message

FAQs

Package last updated on 05 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc