Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 was, in the logs as well. How do I do that?

Thanks!

like image 811
Albert Avatar asked May 10 '11 03:05

Albert


3 Answers

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

like image 182
Calvin Avatar answered Oct 21 '22 03:10

Calvin


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)
like image 20
Bryce Cutt Avatar answered Oct 21 '22 02:10

Bryce Cutt


I think this should help you

import logging

try:
    #exception code
except Exception as e:
    logging.error(e)
like image 41
Abdul Kader Avatar answered Oct 21 '22 02:10

Abdul Kader