トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

PRG-PY-delegate_log

Delegated のログが900Mと大きくなりログの収集にできなくなったので

前処理 分解して CSV に書き出し

#!/bin/env python3
# -*- coding: utf-8 -*-

import re

fr = open('./D/2020Feb.log','r', encoding='utf-8', errors='ignore')
fw = open('test.csv', 'w', encoding='utf-8')
line = fr.readline()
while line:
   fline = re.sub(r'^(\S+) (\S+) (\S+) \[([^\]]+)\] "([A-Z]+) ([^ "]+)? HTTP/[0-9.]+" ([0-9]{3}) ([0-9]+|-)', r'\1,\2,\3,\4,\5,\6,\7,\8', line)
   fw.write(fline)
   # print (fline)
   line = fr.readline()
fr.close()
fw.close()