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 = ; ;
Follow the codes below to generate the configure
object.
var path = ; var separator = '•-•'; // separator of the logvar src = path; // path of the logvar dist = path; // the generated JSON filevar removeSrc = true; // remove the log when JSON is // generated, by default is truevar 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} { var name = 'transformed'; var value = ; return name value;} // what we needvar configure = map separator src dist removeSrc;
Test
simply run npm test
on your favor terminal app.