简体   繁体   English

Python试用除外:如何使Logging.info可变化?

[英]Python Try-Except: How to variabilize Logging.info?

This would be the funniest thing you see all day. 这将是您整天看到的最有趣的事情。 But here it is. 但是在这里。 How do I turn my printed-out exception message into a variable, so I can globalize and update them into my database? 如何将打印出的异常消息转换为变量,以便对其进行全球化并将其更新到数据库中?

Here is the analogy: 这是一个比喻:

try:

except Exception as e:
        logging.error(traceback.format_exc())

This is what I'm currently doing: 这是我目前正在做的:

try:

except Exception as e:
        logging.error(traceback.format_exc())
        loginerror = logging.error(traceback.format_exc())
        print str(loginerror)

So,I basically get None, because clearly it hasn't been variablized: 所以,我基本上得到None,因为显然它没有变化:

None

If needed, here's what my exception message prints out: 如果需要,这是我的异常消息输出的内容:

2018-08-10 09:38:00,009 - root - ERROR - Traceback (most recent call last):
  File "C:\jobtech-crawlers\crawler_parttimejobs.py", line 122, in dump_parttimejobs
    response = requests_retry_session().get(url=linkWqery)
NameError: global name 'linkWqery' is not defined

If you remove the logging.error, it returns a string of the error message. 如果删除logging.error,它将返回错误消息的字符串。

try:
    print(0/0)
except Exception as e:
    x = traceback.format_exc()

print(x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM