ALB Log Parser

0.0.8 · maintenance · verified Tue Apr 21

alb-log-parser is a utility library for Node.js designed to parse Application Load Balancer (ALB) access logs generated by AWS. It provides a function to convert raw ALB log strings into structured JavaScript objects, mapping all fields defined by AWS, including recent additions like `target_group_arn`, `trace_id`, and `classification`. The current stable version is 0.0.8, with the last publish date being July 11, 2021. As a fork of `elb-log-parser`, its release cadence is infrequent, primarily focused on adapting to changes in AWS ALB log formats and improving parsing robustness, such as correctly handling `-1` as a numeric value. It differentiates itself by offering comprehensive field support specifically for ALB logs, making it suitable for serverless architectures (e.g., AWS Lambda) that process logs from S3 buckets for analysis in systems like Elasticsearch.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `alb-log-parser` and use its primary `parse` function to convert a raw ALB access log string into a structured JavaScript object. It shows both installation and basic API usage with a sample log line.

npm install alb-log-parser
// or npm install -g alb-log-parser for global CLI usage

const parse = require('alb-log-parser');

const albLogLine = 'http 2020-08-27T16:35:00.166351Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 192.168.201.251:80 0.000 0.440 0.000 200 200 1107 11912 "GET http://example.com:80/path?foo=bar&baz=bak HTTP/1.1" "Fake/1.0.0 (Linux)" - - arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-tg/ffffffffffffffff "Self=1-00000000-111111111111111111111111;Root=1-00000000-222222222222222222222222" "-" "-" 0 2020-08-27T16:34:59.725000Z "forward" "-" "-" "192.168.201.251:80" "200" "-" "-"';

const parsedLog = parse(albLogLine);
console.log(JSON.stringify(parsedLog, null, 2));

// Example for accessing specific fields
console.log(`
Client IP: ${parsedLog.client}`)
console.log(`Request Method: ${parsedLog.request_method}`)
console.log(`Target Status Code: ${parsedLog.target_status_code}`)

view raw JSON →