Skip to content

Commit

Permalink
Merge pull request #1 from rpaterson/cmdline
Browse files Browse the repository at this point in the history
Add command-line usage
  • Loading branch information
toshihirock committed Apr 22, 2016
2 parents cd8fa44 + 4f914d1 commit fe2e8ec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![npm version](https://badge.fury.io/js/elb-log-parser.png)](https://badge.fury.io/js/elb-log-parser)
[![Build Status](https://travis-ci.org/toshihirock/node-elb-log-parser.svg?branch=master)](https://travis-ci.org/toshihirock/node-elb-log-parser)

A basic parser for ELB access logs, strongly inspired by node-clf-parser https://github.com/jfhbrook/node-clf-parser
A basic parser for ELB access logs, strongly inspired by node-clf-parser https://github.com/jfhbrook/node-clf-parser.

## When I use this npm?

Expand All @@ -13,10 +13,17 @@ A basic parser for ELB access logs, strongly inspired by node-clf-parser https:/
## Install

```
$npm install elb-log-parser
npm install -g elb-log-parser
```

## Example
## Example command-line usage

```
906058675309_elasticloadbalancing_us-east-1_my-elb_20160420T1700Z_10.0.33.113_115hdtdv.log > elb-log-parser
```
Outputs JSON which can then be further processed with e.g. something like the [json](https://www.npmjs.com/package/json) tool.

## Example API usage

```
node-elb-log-parser$node
Expand Down
18 changes: 18 additions & 0 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /usr/bin/env node
module.exports = function (line) {
var parsed = {};
var url = require('url');
Expand Down Expand Up @@ -103,3 +104,20 @@ module.exports = function (line) {

return parsed;
};

if (require.main === module) {
var split = require('split');
var Transform = require('stream').Transform;
process.stdin
.pipe(split())
.pipe(new Transform({
decodeStrings: false,
transform: function (line, encoding, callback) {
if (line) {
this.push(JSON.stringify(module.exports(line)) + '\n');
}
callback();
}
}))
.pipe(process.stdout);
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.0.2",
"description": "A basic parser for ELB access logs, strongly inspired by node-clf-parser https://github.com/jfhbrook/node-clf-parser",
"main": "index.js",
"bin": {
"elb-log-parser": "index.js"
},
"scripts": {
"test": "node ./test.js"
},
Expand All @@ -20,5 +23,8 @@
"license": "MIT",
"devDependencies": {
"tap": "~0.4.3"
},
"dependencies": {
"split": "^1.0.0"
}
}

0 comments on commit fe2e8ec

Please sign in to comment.