Socket
Book a DemoInstallSign in
Socket

log2json

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log2json

transform nginx log to JSON

1.1.1
latest
Source
npmnpm
Version published
Weekly downloads
8
-20%
Maintainers
1
Weekly downloads
 
Created
Source

Log2JSON

Log2JSON is a small lib that allows you to transform nginx/apache/whatever logs to JSON.

Install it will npm / cnpm:

$ npm install log2json

Usage

Run it like:

var log2json = require('log2json');

log2json(configure, ret => {
  if(!ret) return console.log('the file is empty');
  console.log('JSON is generated: %s', ret);
});

Follow the codes below to generate the configure object.

var path = require('path');


var separator = '•-•';                          // separator of the log
var src = path.join(__dirname, './log');        // path of the log
var dist = path.join(__dirname, './log.json');  // the generated JSON file
var removeSrc = true;                           // remove the log when JSON is
                                                //  generated, by default is true
var map = [                                     // map the fields with keys

  'fieldName2',             // 1. {string} name to the filed
  fn2TransformData,         // 2. a custom function to transform the field
                            //    should return an object {name, value}
  'fieldName|number',       // 3. use built-in directive to
                            //    transform the field
  'fieldName|url',          //    built-in directives: number, url, array
  'fieldName|array'         //    - `number` transform string to number
                            //    - `array` transform 'a,b' to ["a","b"]
                            //    - `url` transform querystring to object
                            //      'a=b&c[]=d&c[]=e' to {a:"b", c: ["d", "e"]}
];

// a transform function should return an object like {name, value}
function fn2TransformData(input) {
  var name = 'transformed';
  var value = doSomethingWith(value);
  return {name, value};
}

// what we need
var configure = {map, separator, src, dist, removeSrc};

Test

simply run npm test on your favor terminal app.

Keywords

nginx

FAQs

Package last updated on 27 Nov 2015

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.