Skip to content

Commit

Permalink
Merge branch 'option_save_output_only'
Browse files Browse the repository at this point in the history
  • Loading branch information
lanjelot committed Oct 17, 2019
2 parents 95ffe43 + 3135ea1 commit 7751130
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions patator.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def filter(self, record):
else:
return 1

def process_logs(queue, indicatorsfmt, argv, log_dir):
def process_logs(queue, indicatorsfmt, argv, log_dir, runtime_file):

ignore_ctrlc()

Expand All @@ -765,14 +765,21 @@ def process_logs(queue, indicatorsfmt, argv, log_dir):

names = [name for name, _ in indicatorsfmt] + ['candidate', 'num', 'mesg']

if log_dir:
runtime_log = os.path.join(log_dir, 'RUNTIME.log')
results_csv = os.path.join(log_dir, 'RESULTS.csv')
results_xml = os.path.join(log_dir, 'RESULTS.xml')
if runtime_file or log_dir:
runtime_log = os.path.join(log_dir or '', runtime_file or 'RUNTIME.log')

with open(runtime_log, 'a') as f:
f.write('$ %s\n' % ' '.join(argv))

handler_log = logging.FileHandler(runtime_log)
handler_log.setFormatter(TXTFormatter(indicatorsfmt))

logger.addHandler(handler_log)

if log_dir:
results_csv = os.path.join(log_dir, 'RESULTS.csv')
results_xml = os.path.join(log_dir, 'RESULTS.xml')

if not os.path.exists(results_csv):
with open(results_csv, 'w') as f:
f.write('time,level,%s\n' % ','.join(names))
Expand Down Expand Up @@ -815,18 +822,15 @@ def process_logs(queue, indicatorsfmt, argv, log_dir):
f.seek(offset)
f.truncate(f.tell())

handler_log = logging.FileHandler(runtime_log)
handler_csv = logging.FileHandler(results_csv)
handler_xml = logging.FileHandler(results_xml)

handler_csv.addFilter(MsgFilter())
handler_xml.addFilter(MsgFilter())

handler_log.setFormatter(TXTFormatter(indicatorsfmt))
handler_csv.setFormatter(CSVFormatter(indicatorsfmt))
handler_xml.setFormatter(XMLFormatter(indicatorsfmt))

logger.addHandler(handler_log)
logger.addHandler(handler_csv)
logger.addHandler(handler_xml)

Expand Down Expand Up @@ -1396,6 +1400,7 @@ def format_usage(self, usage):
log_grp = OptionGroup(parser, 'Logging')
log_grp.add_option('-l', dest='log_dir', metavar='DIR', help="save output and response data into DIR ")
log_grp.add_option('-L', dest='auto_log', metavar='SFX', help="automatically save into DIR/yyyy-mm-dd/hh:mm:ss_SFX (DIR defaults to '/tmp/patator')")
log_grp.add_option('-R', dest='runtime_file', metavar='FILE', help="save output to FILE")

dbg_grp = OptionGroup(parser, 'Debugging')
dbg_grp.add_option('-d', '--debug', dest='debug', action='store_true', default=False, help='enable debug messages')
Expand Down Expand Up @@ -1451,7 +1456,7 @@ def __init__(self, module, argv):

log_queue = multiprocessing.Queue()

logsvc = multiprocessing.Process(name='LogSvc', target=process_logs, args=(log_queue, module.Response.indicatorsfmt, argv, build_logdir(opts.log_dir, opts.auto_log)))
logsvc = multiprocessing.Process(name='LogSvc', target=process_logs, args=(log_queue, module.Response.indicatorsfmt, argv, build_logdir(opts.log_dir, opts.auto_log), opts.runtime_file))
logsvc.daemon = True
logsvc.start()

Expand Down

0 comments on commit 7751130

Please sign in to comment.