Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logger.info(traceback.print_exc()) coming on python gui

Tags:

python

logging

When I execute logger.info(traceback.print_exc()) the trace gets on console rather than in the log file I have logger.propagate = False also still the same issue

like image 846
Shruts_me Avatar asked May 18 '12 01:05

Shruts_me


People also ask

How do I print a traceback in Python logger?

import traceback traceback. format_exc() # this will print a complete trace to stout. Save this answer.

What is a traceback error in Python?

In Python, A traceback is a report containing the function calls made in your code at a specific point i.e when you get an error it is recommended that you should trace it backward(traceback). Whenever the code gets an exception, the traceback will give the information about what went wrong in the code.

What does Logger error do in Python?

To log an exception in Python we can use logging module and through that we can log the error. Logging an exception in python with an error can be done in the logging. exception() method. This function logs a message with level ERROR on this logger.


2 Answers

print_exc prints the stack trace to stderr.

Just use the exc_info=1 argument and it will automaticaly include the exception.

logging.exception("Exception") #or 
logging.error("exception ",exc_info=1) #or
logging.info("Exception has occured" ,exc_info=1)
like image 104
Nix Avatar answered Sep 21 '22 05:09

Nix


I am using python 2.7 and sadly exc_info=1 never worked for me so I had to use this:

  import traceback
  ...


  log.debug(traceback.format_exc())
like image 39
moin moin Avatar answered Sep 19 '22 05:09

moin moin