NebulousLabs/Sia — pull request #231 by lukechampine (2014-09-12 04:29:00+00:00)
Title: Logger

This PR is the first effort to integrate logging into the Sia codebase. A new logger has been constructed and cautiously deployed. Thus far, I have mainly used it to replace calls to `panic()`. A more thorough inspection of the codebase is necessary to determine what sort of logging operation is appropriate for each circumstance.

The details of the logger are outlined in issue #226, but I will paraphrase them here.
- A logger field has been added to each of the Participant, Engine, and State objects.
- For now, everything uses the "Default" logger, which outputs to stderr.
- Logging operations should be carried out as far up the call chain as possible.
- The new `ctxError` type can be used to construct errors with context.
- Logger initialization is not yet complete.

The logger is far from polished, and I'm sure it will continue to grow and become more useful as it becomes more integrated into the codebase. There are certainly many design decisions that need to be agreed upon. But the initial results are promising. When used properly in conjunction with `ctxError`, the new logger can tell you exactly who called a function, when they called it, and why it failed. I think we'll be very happy to have it when debugging a complex project like Sia.