logview: add gzip compression on logfiles
Signed-off-by: Francois Andrieu <darknao@fedoraproject.org>
This commit is contained in:
parent
09d9f204dd
commit
a221e0db50
2 changed files with 12 additions and 3 deletions
|
@ -21,6 +21,7 @@ import os
|
|||
import time
|
||||
import json
|
||||
import pwd
|
||||
import gzip
|
||||
|
||||
try:
|
||||
from ansible.utils.hashing import secure_hash
|
||||
|
@ -156,7 +157,7 @@ class LogMech(object):
|
|||
name = name.strip()
|
||||
|
||||
sanitize_host = host.replace(' ', '_').replace('>', '-')
|
||||
fd = open(self.logpath_play + '/' + sanitize_host + '.log', 'a')
|
||||
fd = gzip.open(self.logpath_play + '/' + sanitize_host + '.log.gz', 'at')
|
||||
now = time.strftime(TIME_FORMAT, time.localtime())
|
||||
fd.write(MSG_FORMAT % dict(now=now, name=name, count=count, category=category, data=json.dumps(data)))
|
||||
fd.close()
|
||||
|
|
|
@ -5,6 +5,7 @@ from optparse import OptionParser
|
|||
import os
|
||||
import glob
|
||||
from datetime import date, timedelta
|
||||
import gzip
|
||||
import dateutil.parser as dateparser
|
||||
|
||||
logpath = '/var/log/ansible'
|
||||
|
@ -53,9 +54,16 @@ def parse_args(args):
|
|||
def search_logs(opts, logfiles):
|
||||
msg = ''
|
||||
for fn in sorted(logfiles):
|
||||
hostname = os.path.basename(fn).replace('.log', '')
|
||||
hostname = os.path.basename(fn).replace('.log', '').replace('.gz', '')
|
||||
timestamp = os.path.basename(os.path.dirname(fn))
|
||||
for line in open(fn):
|
||||
try:
|
||||
with gzip.open(fn) as f:
|
||||
f.read()
|
||||
open_f = gzip.open(fn, "rt")
|
||||
except:
|
||||
open_f = open(fn)
|
||||
|
||||
for line in open_f:
|
||||
things = line.split('\t')
|
||||
if len(things) < 5:
|
||||
msg += "(logview error - unhandled line): %r\n" % line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue