Registry / database / postgres-csvlog

postgres-csvlog

JSON →
library1.0.2jsnpmunverified

A lightweight Node.js library for parsing PostgreSQL logs in CSV format (csvlog). Current stable version is 1.0.2. It is a straightforward, dependency-free parser that converts PostgreSQL csvlog lines into JavaScript objects. Unlike manual parsing or regular expressions, this library handles the custom CSV escaping, quoting, and field types used by PostgreSQL's csvlog format, including timestamps, numeric, and error details. It parses each line according to the PostgreSQL documentation for log_destination='csvlog'. No dependencies, simple API, suitable for log analysis and monitoring tools. Released under the MIT license.

npm install postgres-csvlog
INSTALL
IMPORT
SIG · POSTGRES-CSVLOG
P
postgres-csvlog
databasejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import parse from 'postgres-csvlog'
const { parse } = require('postgres-csvlog')
The package exports a single default function for parsing.
parse
import parse from 'postgres-csvlog'
const parse = require('postgres-csvlog').default
In CommonJS, use require('postgres-csvlog') directly; it's not a named export.
parse (require)
const parse = require('postgres-csvlog')
const { parse } = require('postgres-csvlog')
The module exports the function directly, not as a property.

Parses a single PostgreSQL csvlog line into an object with typed fields.

const parse = require('postgres-csvlog'); const logLine = '2023-01-01 00:00:00.000 UTC,"postgres","postgres",1234,"[local]","5f4e3d2a.1b2c",3,"LOG","00000","connection received: host=127.0.0.1 port=5432",,,,,,,,,"",0,0,"","","",""'; const parsed = parse(logLine); console.log(parsed); // Output object with fields like timestamp, username, database, process_id, etc.
Debug
Known issues
gotchaThe parser expects exactly one complete CSV log line; multiple lines or partial lines will produce incorrect results.
fix
Split multiline logs by newline and parse each line separately.
affects: all
gotchaThe function does not validate the input; passing a non-CSV or malformed line may return an object with missing or undefined fields.
fix
Ensure input adheres to PostgreSQL csvlog format; consider validating with a regex prefix check.
affects: all
gotchaThe parser uses a simple CSV split that may not handle all edge cases of PostgreSQL's csvlog quoting (e.g., embedded commas in quoted fields are supported, but newlines inside quotes are not).
fix
For robust handling, use PostgreSQL's COPY command to export logs if possible.
affects: all
Errors
Common errors & fixes
TypeError: parse is not a function
Using named import instead of default import or require.
fix
Use `import parse from 'postgres-csvlog'` or `const parse = require('postgres-csvlog')`
Cannot read property 'timestamp' of undefined
Passing an empty string or undefined to the parse function.
fix
Ensure the log line is a non-empty string before calling parse.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
34
Bingbot
4
Resources
postgres-csvlog — npm install postgres-csvlog · libregistry