astropy/astropy — pull request #192 by astrofrog (2012-04-06 21:18:33+00:00)
Title: Advanced logger implementation based on logging module 

This PR replaces #93 and #183, and implements a logging system based on the requirements in https://github.com/astropy/astropy/wiki/Logging, discussions on the astropy-dev mailing list, and discussions in #93 and #183. I think all concerns have been addressed (though there are a few open questions below).

The current implementation relies on the logging module, and extends the Logger class to provide additional functionality, including:

* optional coloring of messages
* keeping track of the module that called the log (this adds an `origin` keyword to `LogRecord` entries)
* a context manager to capture logging entries to a list
* a context manager to write logging entries to a file
* the ability to enable/disable catching of ``warnings.warn`` entries
* the ability to insert entries for uncaught exceptions in the log
* the ability to control various aspects of the logging via the Astropy configuration file(s)

The following examples demonstrate the functionality: https://gist.github.com/2322952 (too many examples to show here).

If this implementation looks better than the previous PRs, then I will close #93 and #183.

Remaining open questions:

* I need to figure out how to set the origin correctly for the uncaught exceptions when catching these - any ideas?
* When we use a context manager, do we want log messages *not* to appear in stdout?
* Do we want each sub-package in Astropy to use a different instance of the logging class, or is the current implementation fine? If the former, rather than import ``logger``, modules could import ``get_logger`` which would return a logger with the right hierarchy (using ``find_current_module``). However, this could get a bit confusing, and I'm not sure what the advantages are compared to the current implementation. Any thoughts?

Once we've converged on the API, I'll write up docs and tests (but as before, there is no point in writing these if the code and API are going to change significantly)

Let me know if you have any feedback/suggestions!