Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] gcp_csv2log: add script to convert google cloud platform in postgresql log #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions gcp_csv2log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Convert Google Cloud Platform log in cvs to postgresql log
"""
import csv
import os

from file_read_backwards import FileReadBackwards


def get_psql_log_from_gcp_csv(gcp_csv_file):

fname_logs_temp = "postgresql_temp.csv"

if not os.path.exists(gcp_csv_file):
return

with open(gcp_csv_file) as csvfile:
reader = csv.DictReader(csvfile)
with open(fname_logs_temp, "a") as log_temp:
for row in reader:
log_temp.write("{column} \n".format(column=row["textPayload"]))

with FileReadBackwards(fname_logs_temp, encoding="utf-8") as frb:
with open("postgresql.log", "a") as log:
for line in frb:
if line and line is not None:
log.write("{column} \n".format(column=line))

if os.path.isfile(fname_logs_temp):
os.remove(fname_logs_temp)