ts = str(datetime.datetime.now())
log = "DIF_logfile_" + ts
logging.basicConfig(filename=log, format='%(asctime)s %(message)s', filemode='w')
logger = logging.getLogger()
config.read(sys.argv[1])
mode = logger.error
logger.setLevel(mode)
for tbl in table:
try:hive_tbl = config.get(tbl, "hive_tbl")
except:logger.error("Table doesn't exists")
#except:print "Table doesn't exists"
当传递的tbl值错误时,我无法将异常写入日志文件,但是如果我在控制台中打印它的进来。我正在从配置文件传递tbl值。
答案 0 :(得分:0)
这些代码甚至不起作用,这些行:
logger = logging.getLogger()
mode = logger.error
logger.setLevel(mode)
应该是这样的:
logger = logging.getLogger()
mode = logging.ERROR
logger.setLevel(mode)
我更改了它们后,它开始工作了。还要提一提的是,请确保这些行:
ts = str(datetime.datetime.now())
log = "DIF_logfile_"+ts
创建一个有效的文件名,它们不在我的系统上