-
Notifications
You must be signed in to change notification settings - Fork 0
API Documentation
What do you mean?
Overview: Converts Common Log Format (CLF) into more useful JSON and/or CSV.
Internal implementation: A custom (Duplex) Transform stream.
Getting Started:
When you want to convert CLF to CSV:
const wdymCSV = require('wdym').csv
When you want to convert CLF to JSON:
const wdymJSON = require('wdym').json
-
Class: WDYM
-
.isCLF(line) β
Array
-
.isCLF(line) β
-
Children:
-
WDYM_CSV
-
toCSV(clf) β
String
-
toCSV(clf) β
-
WDYM_JSON
-
toJSON(clf) β
String
-
toJSON(clf) β
-
WDYM_CSV
Kind: global class, no constructor β instance method(s) can only be used through its child classes.
Parent: This class inherits from stream.Transform, allowing the objects of its child classes to be used in pipes and similar stream operations.
Matches the provided line to standardised (ASCII) CLF Log format. If in strict mode, returns the full match only after validation of each log's components (such as remote host and HTTP status code).
Kind: instance method of WDYM
Param | Type | Description |
---|---|---|
line | String |
the string to match |
[options] | Object |
|
[options.strict] | Boolean |
enables strict mode |
Return value: returns an Array
whose contents match the schema below (if the line is in CLF) or null
.
Example:
const wdymCSV = require('wdym').csv
const clf = '127.0.0.1 - g [27/Apr/2012:11:27:36 +0700] "GET /ss.html HTTP/1.1" 200 2326'
const match = wdymCSV.isCLF(clf, { strict: true })
//=> [
// '127.0.0.1 - g [27/Apr/2012:11:27:36 +0700] "GET /ss.html HTTP/1.1" 200 2326',
// '127.0.0.1',
// '-',
// 'g',
// '27/Apr/2012:11:27:36 +0700',
// 'GET /ss.html HTTP/1.1',
// '200',
// '2326',
// ...
// ]
Kind: global class
Parent: WDYM
Parses the CLF logs and converts them to CSV.
Kind: instance method of WDYM_CSV
Param | Type | Description |
---|---|---|
clf | String |
the CLF logs β separated by the newline character |
Throws:
-
IncorrectFormatError
- when one (or more) of the logs is not in CLF -
ValidationError
- when one (or more) of the logs' components fail to validate
Return value: the logs as a single CSV string.
Example:
const wdymCSV = require('wdym').csv
const clf = '127.0.0.1 - g [27/Apr/2012:11:27:36 +0700] "GET /ss.html HTTP/1.1" 200 2326'
const csv = wdymCSV.toCSV(clf)
//=>
// REMOTE HOST,REMOTE LOG NAME,USER ID,DATE,REQUEST,HTTP STATUS CODE,SIZE
// 127.0.0.1,-,g,Fri Apr 27 2012 09:57:36 GMT+0530 (India Standard Time),GET /ss.html HTTP/1.1,200,2326
Kind: global class
Parent: WDYM
Parses the CLF logs and converts them to JSON.
Kind: instance method of WDYM_JSON
Param | Type | Description |
---|---|---|
clf | String |
the CLF logs β separated by the newline character |
Throws:
-
IncorrectFormatError
- when one (or more) of the logs is not in CLF -
ValidationError
- when one (or more) of the logs' components fail to validate
Return value: the logs as a single JSON object that corresponds to the schema in the example below
Example:
const wdymJSON = require('wdym').json
const clf = '127.0.0.1 - g [27/Apr/2012:11:27:36 +0700] "GET /ss.html HTTP/1.1" 200 2326'
const json = wdymJSON.toJSON(clf)
//=> {
// "log": [
// {
// "remoteHost": "127.0.0.1",
// "remoteLogName": "-",
// "authUser": "g",
// "date": "2012-04-27T04:27:36.000Z",
// "request": "GET /ss.html HTTP/1.1",
// "status": 200,
// "size": 2326
// }
// ]
// }
more on .isCLF(line) return value:
[ 0
: input,
1
: remote host/IP Address of the client,
2
: RFC 1413 identity of the client,
3
: user ID,
4
: date,
5
: request,
6
: HTTP status code,
7
: size of the object returned to the client (in bytes),
...
: miscellaneous ]
Β© Abir Bhushan <[email protected]> 2020