Skip to content

Commit

Permalink
[ADD] gcp_csv2log: add script to convert google cloud platform log in…
Browse files Browse the repository at this point in the history
… postgresql.log

Method 'get_psql_log_from_gcp_csv' needs a full path with name file and it'll generate a postgresql.log file
  • Loading branch information
fernandahf committed Jan 21, 2021
1 parent a3811ab commit 7ec5871
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions gcp_csv2log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
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))

0 comments on commit 7ec5871

Please sign in to comment.