开发者

How to log exceptions in appengine?

try:
  #do something that raises an exception...
except:
  logging.error('Error Message')

I want more than just "Error Message" to show in the logs. I want to see the traceback, or at least what the exception wa开发者_如何转开发s, in the logs as well. How do I do that?

Thanks!


logging.exception(msg[, *args])

Logs a message with level ERROR on the root logger. The arguments are interpreted as for debug(). Exception info is added to the logging message. This function should only be called from an exception handler.

http://docs.python.org/library/logging.html#logging.exception


This is what I use to log the entire stack trace:

import traceback
try:
    # your code
except:
    stacktrace = traceback.format_exc()
    logging.error("%s", stacktrace)


I think this should help you

import logging

try:
    #exception code
except Exception as e:
    logging.error(e)


You can set the logging details to Debug,Info,Warning,Error or Critical and set in your application. Debug would give you a lot of details.

import logging
logging.getLogger().setLevel(logging.DEBUG)

And you can get the logs of the particular filter in your appengine web console under /logs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜