不确定为什么我的记录器没有记录任何内容。我的日志文件是由日志文件中没有内容生成的。
设置记录器:
log = logging.getLogger(me)
dt = datetime.datetime.utcnow()
logfile = "qe/logs/" + args.runtag + "_{}_{}_{}".format(dt.month, dt.day, dt.year) + "_cron.log"
if isinstance(logfile,str):
if os.path.exists(logfile):
os.remove(logfile)
log.addHandler(logging.FileHandler(logfile))
console = logging.StreamHandler(sys.stderr); console.setLevel(logging.WARNING); log.addHandler(console)
用法:
log.info("{0}: START: {1}".format(me, datetime.datetime.now().ctime()))
log.info("RUNTAG: {}".format(args.runtag))
TestWildCardEvents(log, test_objs, args.runtag).runTest()
TestWildCardEvents:
class TestWildCardEvents():
def __init__(self, log, test_objs, runtag):
self.log = log
self.test_objs = test_objs
self.runtag = runtag
self.e2e_order = ['post', 'hdfs', 'hive']
def runTest(self):
self.log.info("test")
for phase in self.e2e_order:
phase_obj = jpath_get(self.test_objs, phase)
if phase_obj is not None:
print("test")
我的日志已创建,但文件中没有内容。