3

How can I set error reporting and warning outputs in Python like in PHP error_reporting(E_LEVEL)?

8
  • Why do you want this? What do you want to accomplish? Commented Sep 15, 2010 at 14:35
  • 3
    error_reporting is not responsible for outputs! but for level only. and it should be always at max. just don't touch it not in PHP nor in Python Commented Sep 15, 2010 at 14:40
  • I could be wrong, but the OP is asking for the Python equivalent to PHP's error_reporting. Commented Sep 15, 2010 at 14:47
  • @Gordon in PHP this feature has very limited use. To deal with dirty legacy code only. I doubt it have any good use for Python either. Commented Sep 15, 2010 at 14:55
  • @Col.Shrapnel well, doubting is not knowing ;) especially if you dont even know if an equivalent exists at all. Commented Sep 15, 2010 at 14:57

1 Answer 1

1

A vaguely related option might be the setting of level in the logging module of the Python standard library, and I quote from Python's docs:

import logging
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

logging.debug('This message should go to the log file')

That level= determines which logging messages are emitted and which ones are filtered. However this only applies to errors (and other messages) emitted through logging module functions, not to (e.g) tracebacks resulting from exceptions; if you want to control the latter (what kinds of message come out when the process dies by propagating an exception), you can build something based on sys.excepthook, but your degrees of freedom will still be somewhat limited (in particular, after the reporting -- abundant or scarce as it may be -- the process will exit if an exception has propagated to that point).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.