Skip to content
eteq edited this page Mar 30, 2012 · 5 revisions

It would be good to make sure that all Astropy sub-packages use the same system to print to standard output, so that messages can be filtered (e.g. debug vs production), captured, and automatically include useful information such as the origin of the message.

The purpose of this page is to keep track of the requirements for such a system:

  • There should be at least three levels of output: debug, info, and warning

  • It should be straightforward to filter levels by importance and customize the threshold level, both via a function/method and via the Astropy configuration file.

  • It should be possible to capture logs/messages. One nice way to do this would be via a context manager, e.g.:

    with catch_logs():
        ...
    

    Furthermore, it would be nice to be able to do this based on the origin or importance of the message.

  • It should capture warnings and include them in the log. (@eteq: This is preliminary, as it is an "answer" to one of the questions below - it might be we simply say "don't use the warning system" instead.)

  • If an unhandled exception is thrown, it should appear as an entry in the log with the relevant traceback info. This can be done by replacing sys.excepthook (@eteq : also an answer to a question below)

Open questions:

  • How would warnings integrate with the standard warnings module? (@eteq : It should either integrate with it - e.g. warnings get translated into log entries, probably via logging.capture_warnings, or warnings should not be used, and instead the warning log should be caught to respond to warnings as appropriate.)
  • Do we want this to somehow catch exceptions? (@eteq : yes - see the requirement I added above)
  • Do we want to be able to change the settings for filtering on a per-subpackage basis? (@eteq : those would be nice, so perhaps leave this option open in the future, but not include it in an initial implementation)

At the moment, #93 and #183 both contain example implementations, but should just be considered prototypes, as they are both still inadequate.

Clone this wiki locally