#!/usr/bin/env python
import sys
import logging
import time
import subprocess

logger = logging.getLogger('logname')
timestr = time.strftime("%Y%m%d-%H%M%S")
hdlr = logging.FileHandler('filepath' + timestr)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)

logger.info('SomeInfo: ' + time.strftime("%Y%m%d-%H%M%S"))

p = subprocess.Popen('impala-shell -k --ssl -i <worker_node> -f <file_path>', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
    logger.info(line)
    print line,
retval = p.wait()

logger.info('someInfo: ' + time.strftime("%Y%m%d-%H%M%S"))
