Skip to content

Instantly share code, notes, and snippets.

@madprog
Created September 11, 2019 16:30
Show Gist options
  • Save madprog/b828a854f04ae18e881eff513a6123a7 to your computer and use it in GitHub Desktop.
Save madprog/b828a854f04ae18e881eff513a6123a7 to your computer and use it in GitHub Desktop.
Odoo log splitter
import os
import sys
import time
def split_files(path):
path_dir = os.path.join(os.path.dirname(path), 'extracted_' + time.asctime())
if not os.path.exists(path_dir):
os.mkdir(path_dir)
outputs = {}
with open(path, 'r') as big_file:
output = None
for line in big_file:
year = line[:4]
if year.isnumeric() and int(year) > 2000:
try:
log_date, log_time, log_pid, log_level, log_db, log_message = line.split(' ', 5)
if log_db == '?':
log_db = 'server_db'
output = outputs.get(log_db, None)
if not output:
output = open(os.path.join(path_dir, log_db + '.log'), 'w')
outputs[log_db] = output
except ValueError:
# if we could not assign the split, consider that it is a continuation line
pass
if output:
output.write(line)
for output in outputs.values():
output.close()
if __name__ == '__main__':
if len(sys.argv) != 2:
print('log_split requires exactly one argument: the path to the file')
sys.exit(1)
split_files(os.path.realpath(sys.argv[1]))
@jev-odoo
Copy link

And, when the patch to retrieve logs from saas server is up, it could be combined to automatically retrieve only the relevant logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment