Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""Simple script to read stdin postgresql csv logs and output the SQL statements
To use, do something like this:
tail -f /path/to/your/postgres.log | python -u parse-postgresql-logs.py
"""
import csv
import sys
from functools import partial
try:
import sqlparse
formatter = partial(sqlparse.format, reindent=True)
except ImportError:
formatter = lambda l: l
reader = csv.reader(iter(sys.stdin.readline, ''))
for row in reader:
try:
print formatter(row[13])
except IndexError:
print row
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.