Last active
September 1, 2015 19:44
-
-
Save brianz/39a22f52c7b0fe5e6bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment